-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
13 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
}) |