mirror of
https://github.com/kailong321200875/vue-element-plus-admin.git
synced 2024-11-21 00:51:22 +08:00
perf: 优化启动速度
This commit is contained in:
parent
3a5db42c97
commit
379b340750
@ -1,5 +1,5 @@
|
||||
# 环境
|
||||
NODE_ENV=development
|
||||
VITE_NODE_ENV=development
|
||||
|
||||
# 接口前缀
|
||||
VITE_API_BASE_PATH=
|
||||
@ -9,3 +9,6 @@ VITE_BASE_PATH=/
|
||||
|
||||
# 标题
|
||||
VITE_APP_TITLE=ElementAdmin
|
||||
|
||||
# 是否全量引入element-plus样式
|
||||
VITE_USE_ALL_ELEMENT_PLUS_STYLE=true
|
||||
|
5
.env.dev
5
.env.dev
@ -1,5 +1,5 @@
|
||||
# 环境
|
||||
NODE_ENV=production
|
||||
VITE_NODE_ENV=production
|
||||
|
||||
# 接口前缀
|
||||
VITE_API_BASE_PATH=
|
||||
@ -24,3 +24,6 @@ VITE_APP_TITLE=ElementAdmin
|
||||
|
||||
# 是否包分析
|
||||
VITE_USE_BUNDLE_ANALYZER=false
|
||||
|
||||
# 是否全量引入element-plus样式
|
||||
VITE_USE_ALL_ELEMENT_PLUS_STYLE=false
|
||||
|
@ -1,5 +1,5 @@
|
||||
# 环境
|
||||
NODE_ENV=production
|
||||
VITE_NODE_ENV=production
|
||||
|
||||
# 接口前缀
|
||||
VITE_API_BASE_PATH=
|
||||
@ -23,4 +23,7 @@ VITE_OUT_DIR=dist-pro
|
||||
VITE_APP_TITLE=ElementAdmin
|
||||
|
||||
# 是否包分析
|
||||
VITE_USE_BUNDLE_ANALYZER=false
|
||||
VITE_USE_BUNDLE_ANALYZER=false
|
||||
|
||||
# 是否全量引入element-plus样式
|
||||
VITE_USE_ALL_ELEMENT_PLUS_STYLE=false
|
5
.env.pro
5
.env.pro
@ -1,5 +1,5 @@
|
||||
# 环境
|
||||
NODE_ENV=production
|
||||
VITE_NODE_ENV=production
|
||||
|
||||
# 接口前缀
|
||||
VITE_API_BASE_PATH=
|
||||
@ -24,3 +24,6 @@ VITE_APP_TITLE=ElementAdmin
|
||||
|
||||
# 是否包分析
|
||||
VITE_USE_BUNDLE_ANALYZER=true
|
||||
|
||||
# 是否全量引入element-plus样式
|
||||
VITE_USE_ALL_ELEMENT_PLUS_STYLE=false
|
||||
|
@ -1,5 +1,5 @@
|
||||
# 环境
|
||||
NODE_ENV=production
|
||||
VITE_NODE_ENV=production
|
||||
|
||||
# 接口前缀
|
||||
VITE_API_BASE_PATH=
|
||||
@ -24,3 +24,6 @@ VITE_APP_TITLE=ElementAdmin
|
||||
|
||||
# 是否包分析
|
||||
VITE_USE_BUNDLE_ANALYZER=false
|
||||
|
||||
# 是否全量引入element-plus样式
|
||||
VITE_USE_ALL_ELEMENT_PLUS_STYLE=false
|
||||
|
@ -4,6 +4,7 @@ import { useAppStore } from '@/store/modules/app'
|
||||
import { ConfigGlobal } from '@/components/ConfigGlobal'
|
||||
import { useDesign } from '@/hooks/web/useDesign'
|
||||
import { useDark } from '@vueuse/core'
|
||||
// import { ElNotification } from 'element-plus'
|
||||
|
||||
const { getPrefixCls } = useDesign()
|
||||
|
||||
@ -21,6 +22,14 @@ const isDark = useDark({
|
||||
})
|
||||
|
||||
isDark.value = appStore.getIsDark
|
||||
// ElNotification({
|
||||
// title: '提示',
|
||||
// type: 'warning',
|
||||
// duration: 0,
|
||||
// dangerouslyUseHTMLString: true,
|
||||
// message:
|
||||
// '<div><p><strong>遇事不决,请先查阅常见问题,说不定你能找到相关解答</strong></p><p><a href="https://www.baidu.com" target="_blank">链接地址</a></p></div>'
|
||||
// })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -12,6 +12,12 @@ export const setupElementPlus = (app: App<Element>) => {
|
||||
app.use(plugin)
|
||||
})
|
||||
|
||||
// 为了开发环境启动更快,一次性引入所有样式
|
||||
if (import.meta.env.VITE_USE_ALL_ELEMENT_PLUS_STYLE === 'true') {
|
||||
import('element-plus/dist/index.css')
|
||||
return
|
||||
}
|
||||
|
||||
components.forEach((component) => {
|
||||
app.component(component.name!, component)
|
||||
})
|
||||
|
@ -1,3 +1 @@
|
||||
import 'virtual:svg-icons-register'
|
||||
|
||||
import '@purge-icons/generated'
|
||||
|
@ -20,12 +20,8 @@ module.exports = {
|
||||
'function-no-unknown': null,
|
||||
'no-empty-source': null,
|
||||
'named-grid-areas-no-invalid': null,
|
||||
'unicode-bom': 'never',
|
||||
'no-descending-specificity': null,
|
||||
'font-family-no-missing-generic-family-keyword': null,
|
||||
'declaration-colon-space-after': 'always-single-line',
|
||||
'declaration-colon-space-before': 'never',
|
||||
'declaration-block-trailing-semicolon': null,
|
||||
'rule-empty-line-before': [
|
||||
'always',
|
||||
{
|
||||
|
@ -40,21 +40,23 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
|
||||
}),
|
||||
VueJsx(),
|
||||
progress(),
|
||||
createStyleImportPlugin({
|
||||
resolves: [ElementPlusResolve()],
|
||||
libs: [
|
||||
{
|
||||
libraryName: 'element-plus',
|
||||
esModule: true,
|
||||
resolveStyle: (name) => {
|
||||
if (name === 'click-outside') {
|
||||
return ''
|
||||
env.VITE_USE_ALL_ELEMENT_PLUS_STYLE === 'false'
|
||||
? createStyleImportPlugin({
|
||||
resolves: [ElementPlusResolve()],
|
||||
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`
|
||||
}
|
||||
}
|
||||
]
|
||||
}),
|
||||
]
|
||||
})
|
||||
: undefined,
|
||||
EslintPlugin({
|
||||
cache: false,
|
||||
include: ['src/**/*.vue', 'src/**/*.ts', 'src/**/*.tsx'] // 检查的文件
|
||||
@ -120,7 +122,16 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
|
||||
}
|
||||
},
|
||||
rollupOptions: {
|
||||
plugins: env.VITE_USE_BUNDLE_ANALYZER === 'true' ? [visualizer()] : undefined
|
||||
plugins: env.VITE_USE_BUNDLE_ANALYZER === 'true' ? [visualizer()] : undefined,
|
||||
// 拆包
|
||||
output: {
|
||||
manualChunks: {
|
||||
vue: ['vue', 'vue-router', 'pinia', 'vue-i18n'],
|
||||
'element-plus': ['element-plus'],
|
||||
'wang-editor': ['@wangeditor/editor', '@wangeditor/editor-for-vue'],
|
||||
echarts: ['echarts', 'echarts-wordcloud']
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
server: {
|
||||
|
Loading…
Reference in New Issue
Block a user