From 22c90fa95942464d4aee4f2be9dde17729257fdb Mon Sep 17 00:00:00 2001 From: wangxiang <1827945911@qq.com> Date: Tue, 19 Apr 2022 17:59:12 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=9F=20=E6=9E=84=E5=BB=BA=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E4=B8=9A=E5=8A=A1=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kicc-ui/build/vite/plugin/compImport.ts | 19 ++++ kicc-ui/build/vite/plugin/index.ts | 4 + kicc-ui/package.json | 1 + kicc-ui/src/components/registerGlobComp.ts | 18 ---- kicc-ui/src/main.ts | 6 +- kicc-ui/yarn.lock | 111 ++++++++++++++++++++- 6 files changed, 133 insertions(+), 26 deletions(-) create mode 100644 kicc-ui/build/vite/plugin/compImport.ts delete mode 100644 kicc-ui/src/components/registerGlobComp.ts diff --git a/kicc-ui/build/vite/plugin/compImport.ts b/kicc-ui/build/vite/plugin/compImport.ts new file mode 100644 index 00000000..e66943db --- /dev/null +++ b/kicc-ui/build/vite/plugin/compImport.ts @@ -0,0 +1,19 @@ +/** + * @program: kicc-ui + * @description: unplugin-vue-components配置 + * 提供对vite的按需引入antd组件功能 + * 文档: https://github.com/anncwb/vite-plugin-style-import + * @author: entfrm开发团队-王翔 + * @create: 2022/4/5 + */ + +import Components from 'unplugin-vue-components/vite'; +import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'; + +export function compImportPlugin(isBuild: boolean) { + if (!isBuild) return []; + const comps = Components({ + resolvers: [AntDesignVueResolver()] + }); + return comps; +} diff --git a/kicc-ui/build/vite/plugin/index.ts b/kicc-ui/build/vite/plugin/index.ts index 660d752c..b22da872 100644 --- a/kicc-ui/build/vite/plugin/index.ts +++ b/kicc-ui/build/vite/plugin/index.ts @@ -20,6 +20,7 @@ import { configThemePlugin } from './theme'; import { configImageminPlugin } from './imagemin'; import { configSvgIconsPlugin } from './svgSprite'; import { configHmrPlugin } from './hmr'; +import { compImportPlugin } from './compImport'; export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) { const { @@ -54,6 +55,9 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) { // vite-plugin-svg-icons,提供对SVG精灵图标系统构建 vitePlugins.push(configSvgIconsPlugin(isBuild)); + // unplugin-vue-components,提供对vite的按需引入antd组件功能 + vitePlugins.push(compImportPlugin(isBuild)); + // vite-plugin-style-import,提供对vite的按需引入组件库样式功能 vitePlugins.push(configStyleImportPlugin(isBuild)); diff --git a/kicc-ui/package.json b/kicc-ui/package.json index 4fd34ede..c802c9a3 100644 --- a/kicc-ui/package.json +++ b/kicc-ui/package.json @@ -80,6 +80,7 @@ "rimraf": "^3.0.2", "rollup-plugin-visualizer": "5.5.2", "typescript": "4.4.2", + "unplugin-vue-components": "^0.19.3", "vite": "^2.5.8", "vite-plugin-compression": "^0.3.5", "vite-plugin-html": "^2.1.0", diff --git a/kicc-ui/src/components/registerGlobComp.ts b/kicc-ui/src/components/registerGlobComp.ts deleted file mode 100644 index 62a5fff9..00000000 --- a/kicc-ui/src/components/registerGlobComp.ts +++ /dev/null @@ -1,18 +0,0 @@ -import type { App } from 'vue'; -import { Button } from './Button'; -import { - // 需要 - Button as AntButton, - Input, - Layout, -} from 'ant-design-vue'; - -const compList = [AntButton.Group]; - -export function registerGlobComp(app: App) { - compList.forEach((comp) => { - app.component(comp.name || comp.displayName, comp); - }); - - app.use(Input).use(Button).use(Layout); -} diff --git a/kicc-ui/src/main.ts b/kicc-ui/src/main.ts index 6dcc2653..674f7425 100644 --- a/kicc-ui/src/main.ts +++ b/kicc-ui/src/main.ts @@ -12,7 +12,7 @@ import { setupRouterGuard } from '/@/router/guard'; import { setupStore } from '/@/store'; import { setupGlobDirectives } from '/@/directives'; import { setupI18n } from '/@/locales/setupI18n'; -import { registerGlobComp } from '/@/components/registerGlobComp'; +import Antd from "ant-design-vue"; // 在本地开发中不引入按需? // 在按需引入的本地开发中,浏览器请求的数量将增加 20% 左右。 @@ -31,8 +31,8 @@ async function bootstrap() { // 初始化内部系统配置 initAppConfigStore(); - // 注册全局组件 - registerGlobComp(app); + // 注册antd全局组件 + app.use(Antd); // 多语言配置 await setupI18n(app); diff --git a/kicc-ui/yarn.lock b/kicc-ui/yarn.lock index 6f8d6866..6a41defc 100644 --- a/kicc-ui/yarn.lock +++ b/kicc-ui/yarn.lock @@ -1919,6 +1919,14 @@ ant-design-vue@2.2.8: vue-types "^3.0.0" warning "^4.0.0" +anymatch@~3.1.2: + version "3.1.2" + resolved "https://registry.npmmirror.com/anymatch/-/anymatch-3.1.2.tgz#c0557c096af32f106198f4f4e2a383537e378716" + integrity sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg== + dependencies: + normalize-path "^3.0.0" + picomatch "^2.0.4" + arch@^2.1.0: version "2.2.0" resolved "https://registry.npmmirror.com/arch/-/arch-2.2.0.tgz#1bc47818f305764f23ab3306b0bfc086c5a29d11" @@ -2157,6 +2165,11 @@ bin-wrapper@^4.0.0, bin-wrapper@^4.0.1, "bin-wrapper@npm:bin-wrapper-china": os-filter-obj "^2.0.0" pify "^4.0.1" +binary-extensions@^2.0.0: + version "2.2.0" + resolved "https://registry.npmmirror.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" + integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== + binary-mirror-config@^1: version "1.40.0" resolved "https://registry.npmmirror.com/binary-mirror-config/-/binary-mirror-config-1.40.0.tgz#81ccf6084057e5e7e6127874fa539f3c3fe43a45" @@ -2197,6 +2210,13 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" +brace-expansion@^2.0.1: + version "2.0.1" + resolved "https://registry.npmmirror.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" + integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== + dependencies: + balanced-match "^1.0.0" + braces@^2.2.2: version "2.3.2" resolved "https://registry.npmmirror.com/braces/-/braces-2.3.2.tgz#5979fd3f14cd531565e5fa2df1abfff1dfaee729" @@ -2213,7 +2233,7 @@ braces@^2.2.2: split-string "^3.0.2" to-regex "^3.0.1" -braces@^3.0.2: +braces@^3.0.2, braces@~3.0.2: version "3.0.2" resolved "https://registry.npmmirror.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== @@ -2443,6 +2463,21 @@ chardet@^0.7.0: resolved "https://registry.npmmirror.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e" integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA== +chokidar@^3.5.3: + version "3.5.3" + resolved "https://registry.npmmirror.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" + integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw== + dependencies: + anymatch "~3.1.2" + braces "~3.0.2" + glob-parent "~5.1.2" + is-binary-path "~2.1.0" + is-glob "~4.0.1" + normalize-path "~3.0.0" + readdirp "~3.6.0" + optionalDependencies: + fsevents "~2.3.2" + class-utils@^0.3.5: version "0.3.6" resolved "https://registry.npmmirror.com/class-utils/-/class-utils-0.3.6.tgz#f93369ae8b9a7ce02fd41faad0ca83033190c463" @@ -2980,7 +3015,7 @@ debug@^3.2.6: dependencies: ms "^2.1.1" -debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2, debug@^4.3.3: +debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2, debug@^4.3.3, debug@^4.3.4: version "4.3.4" resolved "https://registry.npmmirror.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== @@ -4390,7 +4425,7 @@ gitconfiglocal@^1.0.0: dependencies: ini "^1.3.2" -glob-parent@^5.1.2: +glob-parent@^5.1.2, glob-parent@~5.1.2: version "5.1.2" resolved "https://registry.npmmirror.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4" integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow== @@ -4916,6 +4951,13 @@ is-bigint@^1.0.1: dependencies: has-bigints "^1.0.1" +is-binary-path@~2.1.0: + version "2.1.0" + resolved "https://registry.npmmirror.com/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09" + integrity sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw== + dependencies: + binary-extensions "^2.0.0" + is-boolean-object@^1.1.0: version "1.1.2" resolved "https://registry.npmmirror.com/is-boolean-object/-/is-boolean-object-1.1.2.tgz#5c6dc200246dd9321ae4b885a114bb1f75f63719" @@ -5034,7 +5076,7 @@ is-gif@^3.0.0: dependencies: file-type "^10.4.0" -is-glob@^4.0.0, is-glob@^4.0.1: +is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1: version "4.0.3" resolved "https://registry.npmmirror.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084" integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg== @@ -5530,6 +5572,11 @@ loader-utils@^3.2.0: resolved "https://registry.npmmirror.com/loader-utils/-/loader-utils-3.2.0.tgz#bcecc51a7898bee7473d4bc6b845b23af8304d4f" integrity sha512-HVl9ZqccQihZ7JM85dco1MvO9G+ONvxoGa9rkhzFsneGLKSUg1gJf9bWzhRhcvm2qChhWpebQhP44qxjKIUCaQ== +local-pkg@^0.4.1: + version "0.4.1" + resolved "https://registry.npmmirror.com/local-pkg/-/local-pkg-0.4.1.tgz#e7b0d7aa0b9c498a1110a5ac5b00ba66ef38cfff" + integrity sha512-lL87ytIGP2FU5PWwNDo0w3WhIo2gopIAxPg9RxDYF7m4rr5ahuZxP22xnJHIvaLTe4Z9P6uKKY2UHiwyB4pcrw== + locate-path@^2.0.0: version "2.0.0" resolved "https://registry.npmmirror.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e" @@ -5854,6 +5901,13 @@ minimatch@^3.0.4: dependencies: brace-expansion "^1.1.7" +minimatch@^5.0.1: + version "5.0.1" + resolved "https://registry.npmmirror.com/minimatch/-/minimatch-5.0.1.tgz#fb9022f7528125187c92bd9e9b6366be1cf3415b" + integrity sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g== + dependencies: + brace-expansion "^2.0.1" + minimist-options@4.1.0: version "4.1.0" resolved "https://registry.npmmirror.com/minimist-options/-/minimist-options-4.1.0.tgz#c0655713c53a8a2ebd77ffa247d342c40f010619" @@ -6005,6 +6059,11 @@ normalize-package-data@^3.0.0: semver "^7.3.4" validate-npm-package-license "^3.0.1" +normalize-path@^3.0.0, normalize-path@~3.0.0: + version "3.0.0" + resolved "https://registry.npmmirror.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" + integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== + normalize-range@^0.1.2: version "0.1.2" resolved "https://registry.npmmirror.com/normalize-range/-/normalize-range-0.1.2.tgz#2d10c06bdfd312ea9777695a4d28439456b75942" @@ -6424,7 +6483,7 @@ picocolors@^1.0.0: resolved "https://registry.npmmirror.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c" integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ== -picomatch@^2.2.2, picomatch@^2.3.1: +picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.2.2, picomatch@^2.3.1: version "2.3.1" resolved "https://registry.npmmirror.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42" integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA== @@ -6909,6 +6968,13 @@ readable-stream@^2.0.0, readable-stream@^2.3.0, readable-stream@^2.3.5, readable string_decoder "~1.1.1" util-deprecate "~1.0.1" +readdirp@~3.6.0: + version "3.6.0" + resolved "https://registry.npmmirror.com/readdirp/-/readdirp-3.6.0.tgz#74a370bd857116e245b29cc97340cd431a02a6c7" + integrity sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA== + dependencies: + picomatch "^2.2.1" + redent@^1.0.0: version "1.0.0" resolved "https://registry.npmmirror.com/redent/-/redent-1.0.0.tgz#cf916ab1fd5f1f16dfb20822dd6ec7f730c2afde" @@ -8100,6 +8166,31 @@ universalify@^2.0.0: resolved "https://registry.npmmirror.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== +unplugin-vue-components@^0.19.3: + version "0.19.3" + resolved "https://registry.npmmirror.com/unplugin-vue-components/-/unplugin-vue-components-0.19.3.tgz#4c0aa419d118aee1c010d0da9d38ead45e735d63" + integrity sha512-z/kpYJnqrJuWglDNs7fy0YRHr41oLc07y2TkP3by6DqPb1GG9xGC9SFigeFwd4J7GVTqyFVsnjoeup7uK7I2dA== + dependencies: + "@antfu/utils" "^0.5.0" + "@rollup/pluginutils" "^4.2.0" + chokidar "^3.5.3" + debug "^4.3.4" + fast-glob "^3.2.11" + local-pkg "^0.4.1" + magic-string "^0.26.1" + minimatch "^5.0.1" + resolve "^1.22.0" + unplugin "^0.6.1" + +unplugin@^0.6.1: + version "0.6.2" + resolved "https://registry.npmmirror.com/unplugin/-/unplugin-0.6.2.tgz#5646829e7f8a664c8a4498654f258dc6ad3ebf1f" + integrity sha512-+QONc2uBFQbeo4x5mlJHjTKjR6pmuchMpGVrWhwdGFFMb4ttFZ4E9KqhOOrNcm3Q8NNyB1vJ4s5e36IZC7UWYw== + dependencies: + chokidar "^3.5.3" + webpack-sources "^3.2.3" + webpack-virtual-modules "^0.4.3" + unset-value@^1.0.0: version "1.0.0" resolved "https://registry.npmmirror.com/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559" @@ -8557,6 +8648,16 @@ webidl-conversions@^4.0.2: resolved "https://registry.npmmirror.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad" integrity sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg== +webpack-sources@^3.2.3: + version "3.2.3" + resolved "https://registry.npmmirror.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde" + integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w== + +webpack-virtual-modules@^0.4.3: + version "0.4.3" + resolved "https://registry.npmmirror.com/webpack-virtual-modules/-/webpack-virtual-modules-0.4.3.tgz#cd597c6d51d5a5ecb473eea1983a58fa8a17ded9" + integrity sha512-5NUqC2JquIL2pBAAo/VfBP6KuGkHIZQXW/lNKupLPfhViwh8wNsu0BObtl09yuKZszeEUfbXz8xhrHvSG16Nqw== + whatwg-url@^5.0.0: version "5.0.0" resolved "https://registry.npmmirror.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"