提交 | 用户 | 时间
|
3e359e
|
1 |
import {resolve} from 'path' |
H |
2 |
import type {ConfigEnv, UserConfig} from 'vite' |
|
3 |
import {loadEnv} from 'vite' |
|
4 |
import {createVitePlugins} from './build/vite' |
|
5 |
import {exclude, include} from "./build/vite/optimize" |
820397
|
6 |
// 当前执行node命令时文件夹的地址(工作目录) |
H |
7 |
const root = process.cwd() |
|
8 |
|
|
9 |
// 路径查找 |
|
10 |
function pathResolve(dir: string) { |
|
11 |
return resolve(root, '.', dir) |
|
12 |
} |
|
13 |
|
|
14 |
// https://vitejs.dev/config/ |
3e359e
|
15 |
export default ({command, mode}: ConfigEnv): UserConfig => { |
820397
|
16 |
let env = {} as any |
H |
17 |
const isBuild = command === 'build' |
|
18 |
if (!isBuild) { |
|
19 |
env = loadEnv((process.argv[3] === '--mode' ? process.argv[4] : process.argv[3]), root) |
|
20 |
} else { |
|
21 |
env = loadEnv(mode, root) |
|
22 |
} |
|
23 |
return { |
|
24 |
base: env.VITE_BASE_PATH, |
|
25 |
root: root, |
|
26 |
// 服务端渲染 |
|
27 |
server: { |
|
28 |
port: env.VITE_PORT, // 端口号 |
|
29 |
host: "0.0.0.0", |
|
30 |
open: env.VITE_OPEN === 'true', |
|
31 |
// 本地跨域代理. 目前注释的原因:暂时没有用途,server 端已经支持跨域 |
|
32 |
// proxy: { |
|
33 |
// ['/admin-api']: { |
|
34 |
// target: env.VITE_BASE_URL, |
|
35 |
// ws: false, |
|
36 |
// changeOrigin: true, |
|
37 |
// rewrite: (path) => path.replace(new RegExp(`^/admin-api`), ''), |
|
38 |
// }, |
|
39 |
// }, |
|
40 |
}, |
|
41 |
// 项目使用的vite插件。 单独提取到build/vite/plugin中管理 |
|
42 |
plugins: createVitePlugins(), |
|
43 |
css: { |
|
44 |
preprocessorOptions: { |
|
45 |
scss: { |
3e359e
|
46 |
additionalData: '@use "@/styles/variables.scss" as *;', |
820397
|
47 |
javascriptEnabled: true |
H |
48 |
} |
|
49 |
} |
|
50 |
}, |
|
51 |
resolve: { |
|
52 |
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.scss', '.css'], |
|
53 |
alias: [ |
|
54 |
{ |
|
55 |
find: 'vue-i18n', |
|
56 |
replacement: 'vue-i18n/dist/vue-i18n.cjs.js' |
|
57 |
}, |
|
58 |
{ |
|
59 |
find: /\@\//, |
|
60 |
replacement: `${pathResolve('src')}/` |
|
61 |
} |
|
62 |
] |
|
63 |
}, |
|
64 |
build: { |
|
65 |
minify: 'terser', |
|
66 |
outDir: env.VITE_OUT_DIR || 'dist', |
|
67 |
sourcemap: env.VITE_SOURCEMAP === 'true' ? 'inline' : false, |
|
68 |
// brotliSize: false, |
|
69 |
terserOptions: { |
|
70 |
compress: { |
|
71 |
drop_debugger: env.VITE_DROP_DEBUGGER === 'true', |
|
72 |
drop_console: env.VITE_DROP_CONSOLE === 'true' |
|
73 |
} |
3e359e
|
74 |
}, |
H |
75 |
rollupOptions: { |
|
76 |
output: { |
|
77 |
manualChunks: { |
|
78 |
echarts: ['echarts'] // 将 echarts 单独打包,参考 https://gitee.com/yudaocode/yudao-ui-admin-vue3/issues/IAB1SX 讨论 |
|
79 |
} |
|
80 |
}, |
|
81 |
}, |
820397
|
82 |
}, |
3e359e
|
83 |
optimizeDeps: {include, exclude} |
820397
|
84 |
} |
H |
85 |
} |