-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathvite.config.ts
36 lines (34 loc) · 1.16 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { resolve } from 'path';
import { ConfigEnv, UserConfigExport } from 'vite';
import { serverOptions, generatePlugins } from './build';
const currentTimestamp = new Date().getTime();
const nodeModulesFileName = `vendor_${currentTimestamp}`;
export default ({ mode, command }: ConfigEnv): UserConfigExport => ({
base: './',
// Development server config
server: serverOptions,
resolve: {
// Alias config
alias: {
'~': resolve(__dirname, 'src/'),
},
},
// Plugins config
plugins: generatePlugins(command, mode, currentTimestamp),
// Build config
build: {
rollupOptions: {
// Vite < 2.9.0 does not automatically split vendor chunks when using the build command.
// Reference: https://cn.vitejs.dev/guide/build.html#chunking-strategy
output: {
// https://www.rollupjs.com/guide/big-list-of-options#outputmanualchunks
// 将 node_modules 中的模块打包到自定义 vendor chunk 中,利用浏览器缓存机制,加快页面加载速度
manualChunks: (id) => {
if (id.includes('node_modules')) {
return nodeModulesFileName;
}
},
},
},
},
});