-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
96 lines (91 loc) · 2.17 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import legacy from '@vitejs/plugin-legacy';
import react from '@vitejs/plugin-react';
import autoprefixer from 'autoprefixer';
import fs from 'fs';
import path from 'path';
import px2rem from 'postcss-pxtorem';
import { defineConfig } from 'vite';
import { dependencies } from './package.json';
import uiConfig from './src/ui.config.json';
// 打包时,生成一些基础的构建信息到 build.json
if (process.env.VITE_MODE !== 'local') {
fs.writeFileSync(
path.join(__dirname, './public/build.json'),
JSON.stringify({
version: `${Date.now()}`,
}),
);
}
const vendorList = ['react', 'react-router-dom', 'react-dom'];
function renderChunks(deps: Record<string, string>) {
let chunks: Record<string, string[]> = {};
Object.keys(deps).forEach((key) => {
if (vendorList.includes(key)) return;
chunks[key] = [key];
});
return chunks;
}
// https://vitejs.dev/config/
export default defineConfig({
base: '/',
server: {
host: true,
port: 4010,
},
define: {
VITE_MODE: `"${process.env.VITE_MODE}"`,
},
plugins: [
legacy({
targets: ['ie >= 11'],
additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
}),
react(),
],
css: {
modules: {
scopeBehaviour: 'local',
generateScopedName: '[local]_[hash:base64:6]',
},
postcss: {
plugins: [
autoprefixer(),
px2rem({
rootValue: uiConfig.width / uiConfig.base_num,
unitPrecision: 5,
propList: ['*'],
selectorBlackList: [],
replace: true,
mediaQuery: false,
minPixelValue: 1,
// exclude: /node_modules/i,
}),
],
},
preprocessorOptions: {
less: {
javascriptEnabled: true,
modifyVars: { '@primary-color': '#2153D3' },
},
},
},
resolve: {
alias: {
'~': path.resolve(__dirname, './'),
'@': path.resolve(__dirname, 'src'),
},
},
build: {
target: 'es2015',
sourcemap: false,
rollupOptions: {
output: {
// 抽离公共模块代码
manualChunks: {
vendor: vendorList,
...renderChunks(dependencies),
},
},
},
},
});