Skip to content

Commit 833502d

Browse files
committed
feat: On-demand components auto importing for Vue close #7
1 parent 77e1b99 commit 833502d

File tree

8 files changed

+98
-11
lines changed

8 files changed

+98
-11
lines changed

.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ module.exports = {
2020
'import/no-named-as-default': 'off',
2121
'import/namespace': [2, { allowComputed: true }],
2222
'import/no-named-as-default-member': 'off',
23-
'import/no-unresolved': [2, { ignore: ['^@'] }],
24-
'@typescript-eslint/consistent-type-imports': 'error',
23+
'import/no-unresolved': 'off',
24+
'@typescript-eslint/consistent-type-imports': 'off',
2525
// enUS: all rules docs https://eslint.org/docs/rules/
2626
// zhCN: 所有规则文档 https://eslint.bootcss.com/docs/rules/
2727
// 基础规则 全部 ES 项目通用

components.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// generated by unplugin-vue-components
2+
// We suggest you to commit this file into source control
3+
// Read more: https://github.com/vuejs/vue-next/pull/3399
4+
import '@vue/runtime-core'
5+
6+
declare module '@vue/runtime-core' {
7+
export interface GlobalComponents {
8+
VanButton: typeof import('vant/es')['Button']
9+
VanConfigProvider: typeof import('vant/es')['ConfigProvider']
10+
VanSwitch: typeof import('vant/es')['Switch']
11+
}
12+
}
13+
14+
export {}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"postcss-px-to-viewport-8-plugin": "^1.1.3",
4545
"typescript": "^4.5.4",
4646
"umi-mock-middleware2": "^1.0.2",
47+
"unplugin-vue-components": "^0.19.6",
4748
"vite": "^2.9.9",
4849
"vue-tsc": "^0.34.7"
4950
}

src/main.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import router from './router'
44
import { createPinia } from 'pinia'
55

66
import './app.less'
7-
import Vant from 'vant'
8-
import 'vant/lib/index.css'
97

108
// Vant 桌面端适配
119
import '@vant/touch-emulator'
@@ -25,6 +23,5 @@ const app = createApp(App)
2523
app
2624
.use(router)
2725
.use(createPinia())
28-
.use(Vant)
2926

3027
app.mount('#app')

src/views/dashboard/analysis/index.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
</div>
66
</template>
77

8-
<script setup lang="ts"></script>
8+
<script lang="ts">
9+
import { defineComponent } from 'vue'
10+
export default defineComponent({
11+
setup() {
12+
return {}
13+
}
14+
})
15+
</script>
916

1017
<style lang="less" scoped>
1118
.container {

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"src/**/*.tsx",
3030
"src/**/*.vue",
3131
"tests/**/*.ts",
32-
"tests/**/*.tsx"
32+
"tests/**/*.tsx",
33+
"components.d.ts"
3334
]
3435
}

vite.config.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { ConfigEnv, UserConfig } from 'vite'
22
import { loadEnv } from 'vite'
3-
import vue from '@vitejs/plugin-vue'
43
import path from 'path'
4+
import vue from '@vitejs/plugin-vue'
5+
import Components from 'unplugin-vue-components/vite'
6+
import { VantResolver } from 'unplugin-vue-components/resolvers'
57
import createMockServer from './build/mockServer'
68

79
// https://vitejs.dev/config/
@@ -15,7 +17,12 @@ export default ({ mode }: ConfigEnv): UserConfig => {
1517
'process.env.VUE_APP_PUBLIC_PATH': JSON.stringify(env.VITE_APP_PUBLIC_PATH),
1618
},
1719
plugins: [
18-
vue()
20+
vue(),
21+
Components({
22+
dts: true,
23+
resolvers: [VantResolver()],
24+
types: [],
25+
}),
1926
],
2027
resolve: {
2128
alias: {

yarn.lock

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# yarn lockfile v1
33

44

5+
"@antfu/utils@^0.5.1":
6+
version "0.5.2"
7+
resolved "https://registry.yarnpkg.com/@antfu/utils/-/utils-0.5.2.tgz#8c2d931ff927be0ebe740169874a3d4004ab414b"
8+
integrity sha512-CQkeV+oJxUazwjlHD0/3ZD08QWKuGQkhnrKo3e6ly5pd48VUpXbb77q0xMU4+vc2CkJnDS02Eq/M9ugyX20XZA==
9+
510
"@babel/parser@^7.16.4":
611
version "7.18.4"
712
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.18.4.tgz#6774231779dd700e0af29f6ad8d479582d7ce5ef"
@@ -69,6 +74,14 @@
6974
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.5.tgz#db5a11bf66bdab39569719555b0f76e138d7bd64"
7075
integrity sha512-9X2obfABZuDVLCgPK9aX0a/x4jaOEweTTWE2+9sr0Qqqevj2Uv5XorvusThmc9XGYpS9yI+fhh8RTafBtGposw==
7176

77+
"@rollup/pluginutils@^4.2.1":
78+
version "4.2.1"
79+
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-4.2.1.tgz#e6c6c3aba0744edce3fb2074922d3776c0af2a6d"
80+
integrity sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==
81+
dependencies:
82+
estree-walker "^2.0.1"
83+
picomatch "^2.2.2"
84+
7285
"@types/body-parser@*":
7386
version "1.19.2"
7487
resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.19.2.tgz#aea2059e28b7658639081347ac4fab3de166e6f0"
@@ -1404,7 +1417,7 @@ estraverse@^5.1.0, estraverse@^5.2.0:
14041417
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.3.0.tgz#2eea5290702f26ab8fe5370370ff86c965d21123"
14051418
integrity sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==
14061419

1407-
estree-walker@^2.0.2:
1420+
estree-walker@^2.0.1, estree-walker@^2.0.2:
14081421
version "2.0.2"
14091422
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-2.0.2.tgz#52f010178c2a4c117a7757cfe942adb7d2da4cac"
14101423
integrity sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==
@@ -2230,6 +2243,11 @@ liftoff@^4.0.0:
22302243
rechoir "^0.8.0"
22312244
resolve "^1.20.0"
22322245

2246+
local-pkg@^0.4.1:
2247+
version "0.4.1"
2248+
resolved "https://registry.yarnpkg.com/local-pkg/-/local-pkg-0.4.1.tgz#e7b0d7aa0b9c498a1110a5ac5b00ba66ef38cfff"
2249+
integrity sha512-lL87ytIGP2FU5PWwNDo0w3WhIo2gopIAxPg9RxDYF7m4rr5ahuZxP22xnJHIvaLTe4Z9P6uKKY2UHiwyB4pcrw==
2250+
22332251
locate-path@^2.0.0:
22342252
version "2.0.0"
22352253
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
@@ -2290,6 +2308,13 @@ magic-string@^0.25.7:
22902308
dependencies:
22912309
sourcemap-codec "^1.4.8"
22922310

2311+
magic-string@^0.26.1:
2312+
version "0.26.2"
2313+
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.26.2.tgz#5331700e4158cd6befda738bb6b0c7b93c0d4432"
2314+
integrity sha512-NzzlXpclt5zAbmo6h6jNc8zl2gNRGHvmsZW4IvZhTC4W7k4OlLP+S5YLussa/r3ixNT66KOQfNORlXHSOy/X4A==
2315+
dependencies:
2316+
sourcemap-codec "^1.4.8"
2317+
22932318
make-dir@^2.1.0:
22942319
version "2.1.0"
22952320
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-2.1.0.tgz#5f0310e18b8be898cc07009295a30ae41e91e6f5"
@@ -2766,7 +2791,7 @@ picocolors@^1.0.0:
27662791
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"
27672792
integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==
27682793

2769-
picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.3.1:
2794+
picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.2.2, picomatch@^2.3.1:
27702795
version "2.3.1"
27712796
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
27722797
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
@@ -3353,6 +3378,31 @@ unpipe@1.0.0, unpipe@~1.0.0:
33533378
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
33543379
integrity sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==
33553380

3381+
unplugin-vue-components@^0.19.6:
3382+
version "0.19.6"
3383+
resolved "https://registry.yarnpkg.com/unplugin-vue-components/-/unplugin-vue-components-0.19.6.tgz#268f6d2787d96257d5d1698908d8f34ef3ec5803"
3384+
integrity sha512-APvrJ9Hpid1MLT0G4PWerMJgARhNw6dzz0pcCwCxaO2DR7VyvDacMqjOQNC6ukq7FSw3wzD8VH+9i3EFXwkGmw==
3385+
dependencies:
3386+
"@antfu/utils" "^0.5.1"
3387+
"@rollup/pluginutils" "^4.2.1"
3388+
chokidar "^3.5.3"
3389+
debug "^4.3.4"
3390+
fast-glob "^3.2.11"
3391+
local-pkg "^0.4.1"
3392+
magic-string "^0.26.1"
3393+
minimatch "^5.0.1"
3394+
resolve "^1.22.0"
3395+
unplugin "^0.6.3"
3396+
3397+
unplugin@^0.6.3:
3398+
version "0.6.3"
3399+
resolved "https://registry.yarnpkg.com/unplugin/-/unplugin-0.6.3.tgz#b8721e2b163a410a7efed726e6a0fc6fbadf975a"
3400+
integrity sha512-CoW88FQfCW/yabVc4bLrjikN9HC8dEvMU4O7B6K2jsYMPK0l6iAnd9dpJwqGcmXJKRCU9vwSsy653qg+RK0G6A==
3401+
dependencies:
3402+
chokidar "^3.5.3"
3403+
webpack-sources "^3.2.3"
3404+
webpack-virtual-modules "^0.4.3"
3405+
33563406
upper-case-first@^2.0.2:
33573407
version "2.0.2"
33583408
resolved "https://registry.yarnpkg.com/upper-case-first/-/upper-case-first-2.0.2.tgz#992c3273f882abd19d1e02894cc147117f844324"
@@ -3493,6 +3543,16 @@ wcwidth@^1.0.1:
34933543
dependencies:
34943544
defaults "^1.0.3"
34953545

3546+
webpack-sources@^3.2.3:
3547+
version "3.2.3"
3548+
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde"
3549+
integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==
3550+
3551+
webpack-virtual-modules@^0.4.3:
3552+
version "0.4.3"
3553+
resolved "https://registry.yarnpkg.com/webpack-virtual-modules/-/webpack-virtual-modules-0.4.3.tgz#cd597c6d51d5a5ecb473eea1983a58fa8a17ded9"
3554+
integrity sha512-5NUqC2JquIL2pBAAo/VfBP6KuGkHIZQXW/lNKupLPfhViwh8wNsu0BObtl09yuKZszeEUfbXz8xhrHvSG16Nqw==
3555+
34963556
which-boxed-primitive@^1.0.2:
34973557
version "1.0.2"
34983558
resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz#13757bc89b209b049fe5d86430e21cf40a89a8e6"

0 commit comments

Comments
 (0)