Skip to content

Commit

Permalink
perf: 强制预构建
Browse files Browse the repository at this point in the history
  • Loading branch information
lb1129 committed Aug 1, 2023
1 parent bfd098d commit 6ef0d4d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import { defineConfig, loadEnv, type PluginOption } from 'vite'
import viteBaseConfig from './vite.config.base'
import fs from 'node:fs'

// NOTE mergeConfig 对于 defineConfig(() => ({})) 合并无效
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
const plugins: PluginOption[] = []
// if (mode === 'development') {
// }
// 开发环境强制预构建 ant-design-vue 所有组件样式 避免懒加载时造成页面刷新
const optimizeDepsAntdIncludes: string[] = []
if (mode === 'development') {
fs.readdirSync('node_modules/ant-design-vue/es').map((componentName) => {
if (fs.existsSync(`node_modules/ant-design-vue/es/${componentName}/style/index.js`))
optimizeDepsAntdIncludes.push(`ant-design-vue/es/${componentName}/style`)
})
}
return {
base: env.VITE_PUBLIC_URL,
...viteBaseConfig,
plugins: [...(viteBaseConfig.plugins ?? []), ...plugins]
plugins: [...(viteBaseConfig.plugins ?? []), ...plugins],
optimizeDeps: {
include: optimizeDepsAntdIncludes
}
}
})

0 comments on commit 6ef0d4d

Please sign in to comment.