Commit fded4914 authored by guxukai's avatar guxukai

chore: 按需引入全局组件

parent 4e15138d
......@@ -4,6 +4,7 @@ node_modules
src/assets/font/font.*
tailwind.css
auto-imports.d.ts
components.d.ts
# local env files
.env.local
.env.*.local
......
......@@ -73,7 +73,6 @@
"svg-sprite-loader": "^6.0.11",
"typescript": "^4.5.4",
"typescript-json-serializer": "^3.4.4",
"unplugin-auto-import": "^0.5.5",
"unplugin-vue-components": "^0.17.11",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-shell-plugin-next": "^2.2.2"
......
import upperFirst from 'lodash/upperFirst'
import camelCase from 'lodash/camelCase'
import { App } from '@vue/runtime-core'
const path = require('path')
export default {
install: function (app: App) {
const globalComponents = require.context('./', true, /\.(vue|js)$/iu)
globalComponents.keys().forEach(filePath => {
const component = globalComponents(filePath)
let name = path.resolve(filePath, '..')
name = upperFirst(
camelCase(
name
.split('/')
.pop()
.replace(/\.\w+$/u, ''),
),
)
app.component(`G${name}`, component.default || component)
})
},
}
......@@ -4,7 +4,6 @@ import { store } from '@shared/store'
import { createMockServer } from '@shared/mock'
import 'tailwindcss/tailwind.css'
import ElementPlus from 'element-plus'
import Components from '@shared/components/global/index'
import '@shared/assets/sass/index.scss'
import '@assets/icons'
import '@assets/font/font.css'
......@@ -12,4 +11,4 @@ import '@assets/css/tailwind.css'
import { i18n } from '@shared/plugins/i18n'
createMockServer()
export const app = createApp(App)
app.use(store).use(ElementPlus).use(Components).use(i18n)
app.use(store).use(ElementPlus).use(i18n)
......@@ -5,7 +5,6 @@ const sign = process.argv[4]
const webpackBundleAnalyzer = false
const productionGzipExtensions = ['js', 'css']
const Components = require('unplugin-vue-components/webpack')
const AutoImport = require('unplugin-auto-import/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
const { EnvironmentPlugin, ProvidePlugin } = require('webpack')
const { snakeCase, toUpper } = require('lodash')
......@@ -140,11 +139,10 @@ module.exports = defineConfig({
hints: false,
},
plugins: [
AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
dirs: ['src/shared/components/global'],
dts: true,
}),
/* publicPath => PUBLIC_PATH*/
new EnvironmentPlugin(
......
......@@ -1184,7 +1184,7 @@
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.0.tgz#6734f8ebc106a0860dff7f92bf90df193f0935d7"
integrity sha512-zrsUxjLOKAzdewIDRWy9nsV1GQsKBCWaGwsZQlCgr6/q+vjyZhFgqedLfFBuI9anTPEUT4APq9Mu0SZBTzIcGQ==
"@rollup/pluginutils@^4.1.1", "@rollup/pluginutils@^4.1.2":
"@rollup/pluginutils@^4.1.1":
version "4.1.2"
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-4.1.2.tgz#ed5821c15e5e05e32816f5fb9ec607cdf5a75751"
integrity sha512-ROn4qvkxP9SyPeHaf7uQC/GPFY6L/OWy9+bd9AwcjOAWQwxRscoEyAUD8qCY5o5iL4jqQwoLk2kaTKJPb/HwzQ==
......@@ -10696,18 +10696,6 @@ unpipe@1.0.0, unpipe@~1.0.0:
resolved "https://registry.npm.taobao.org/unpipe/download/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
integrity sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=
unplugin-auto-import@^0.5.5:
version "0.5.5"
resolved "https://registry.yarnpkg.com/unplugin-auto-import/-/unplugin-auto-import-0.5.5.tgz#502f47269efdaeb269d54e3e2707634ac9b6a31b"
integrity sha512-PAP/6WdqWtGhlQBvlVZ7qmhHbLcTYSsARtFSbY/jaUx/SaQkRT7SvronHIKEvx4bPmS+l4erQ9gQKSBBPzvUnQ==
dependencies:
"@antfu/utils" "^0.3.0"
"@rollup/pluginutils" "^4.1.2"
local-pkg "^0.4.0"
magic-string "^0.25.7"
resolve "^1.20.0"
unplugin "^0.2.21"
unplugin-vue-components@^0.17.11:
version "0.17.11"
resolved "https://registry.yarnpkg.com/unplugin-vue-components/-/unplugin-vue-components-0.17.11.tgz#ce5ba9692236cdcfa6750c4c7ad999747c3c2db4"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment