Browse Source

types: 修复全局组件属性类型无法推导

kailong321200875 1 year ago
parent
commit
94160c0418
4 changed files with 20 additions and 20 deletions
  1. 0 1
      .prettierignore
  2. 2 2
      src/views/Example/Page/ExampleAdd.vue
  3. 3 3
      types/components.d.ts
  4. 15 14
      vite.config.ts

+ 0 - 1
.prettierignore

@@ -3,7 +3,6 @@
 /dist*
 /public/*
 /docs/*
-/vite.config.ts
 /src/types/env.d.ts
 /docs/**/*
 /plop/**/*

+ 2 - 2
src/views/Example/Page/ExampleAdd.vue

@@ -43,8 +43,8 @@ const save = async () => {
       <BaseButton @click="go(-1)">
         {{ t('common.back') }}
       </BaseButton>
-      <BaseButton type="primary" :loading="loading" @click="save">
-        {{ t('exampleDemo.save') }}
+      <BaseButton type="primary" :loading="loading" @click="save"
+        >{{ t('exampleDemo.save') }}
       </BaseButton>
     </template>
   </ContentDetailWrap>

+ 3 - 3
types/components.d.ts

@@ -1,8 +1,8 @@
 declare module 'vue' {
   export interface GlobalComponents {
-    Icon: (typeof import('../components/Icon/src/Icon.vue'))['default']
-    Permission: (typeof import('../components/Permission/src/Permission.vue'))['default']
-    BaseButton: (typeof import('../components/Button/src/Button.vue'))['default']
+    Icon: (typeof import('../src/components/Icon/index'))['Icon']
+    Permission: (typeof import('../src/components/Permission/index'))['Permission']
+    BaseButton: (typeof import('../src/components/Button/index'))['BaseButton']
   }
 }
 

+ 15 - 14
vite.config.ts

@@ -5,10 +5,10 @@ import Vue from '@vitejs/plugin-vue'
 import VueJsx from '@vitejs/plugin-vue-jsx'
 import progress from 'vite-plugin-progress'
 import EslintPlugin from 'vite-plugin-eslint'
-import { ViteEjsPlugin } from "vite-plugin-ejs"
+import { ViteEjsPlugin } from 'vite-plugin-ejs'
 import { viteMockServe } from 'vite-plugin-mock'
 import PurgeIcons from 'vite-plugin-purge-icons'
-import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite"
+import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
 import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
 import { createStyleImportPlugin, ElementPlusResolve } from 'vite-plugin-style-import'
 import UnoCSS from 'unocss/vite'
@@ -24,7 +24,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
   let env = {} as any
   const isBuild = command === 'build'
   if (!isBuild) {
-    env = loadEnv((process.argv[3] === '--mode' ? process.argv[4] : process.argv[3]), root)
+    env = loadEnv(process.argv[3] === '--mode' ? process.argv[4] : process.argv[3], root)
   } else {
     env = loadEnv(mode, root)
   }
@@ -41,16 +41,18 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
       progress(),
       createStyleImportPlugin({
         resolves: [ElementPlusResolve()],
-        libs: [{
-          libraryName: 'element-plus',
-          esModule: true,
-          resolveStyle: (name) => {
-            if (name === 'click-outside') {
-              return ''
+        libs: [
+          {
+            libraryName: 'element-plus',
+            esModule: true,
+            resolveStyle: (name) => {
+              if (name === 'click-outside') {
+                return ''
+              }
+              return `element-plus/es/components/${name.replace(/^el-/, '')}/style/css`
             }
-            return `element-plus/es/components/${name.replace(/^el-/, '')}/style/css`
           }
-        }]
+        ]
       }),
       EslintPlugin({
         cache: false,
@@ -81,8 +83,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
       ViteEjsPlugin({
         title: env.VITE_APP_TITLE
       }),
-      UnoCSS(),
-      // sveltekit(),
+      UnoCSS()
     ],
 
     css: {
@@ -125,7 +126,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
         '/api': {
           target: 'http://127.0.0.1:8000',
           changeOrigin: true,
-          rewrite: path => path.replace(/^\/api/, '')
+          rewrite: (path) => path.replace(/^\/api/, '')
         }
       },
       hmr: {