-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
82 lines (79 loc) · 2.18 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
import type { UserConfig, ConfigEnv } from 'vite';
import { loadEnv } from 'vite';
import { convertEnv } from './build/utils';
import { resolve } from "path";
import { OUTPUT_DIR } from './build/config';
import { createVitePlugins } from './build/vite/plugin';
// https://vitejs.dev/config/
function pathResolve(dir: string) {
return resolve(process.cwd(), '.', dir);
}
export default ({ command, mode }: ConfigEnv): UserConfig => {
const root = process.cwd(); //返回nodejs当前工作目录
const env = loadEnv(mode, root);
console.log("process.argv", process.argv.splice(2));
//读取env配置布尔类型是字符串,转换成boolean
const viteEnv = convertEnv(env);
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE } = viteEnv;
const isBuild = command === 'build';
// plugins: createVitePlugins(),
// css: {
// //* css模块化
// modules: { // css模块化 文件以.module.[css|less|scss]结尾
// generateScopedName: '[name]__[local]___[hash:base64:5]',
// hashPrefix: 'prefix',
// },
// //* 预编译支持less
// preprocessorOptions: {
// less: {
// // 支持内联 JavaScript
// javascriptEnabled: true,
// },
// },
// },
// base: './'
return {
base: VITE_PUBLIC_PATH,
root,
resolve: {
alias: [
// /@/xxxx => src/xxxx
{
find: /\/@\//,
replacement: pathResolve('src') + '/',
},
{
find: /\/@\//,
replacement: pathResolve('public') + '/',
},
// /#/xxxx => types/xxxx
{
find: /\/#\//,
replacement: pathResolve('types') + '/',
},
],
},
server: {
port: VITE_PORT,
host: true,
open: true,
},
esbuild: {
pure: VITE_DROP_CONSOLE ? ['console.log', 'debugger'] : [],
},
build: {
target: 'es2015',
cssTarget: 'chrome80',
outDir: OUTPUT_DIR,
brotliSize: false,
chunkSizeWarningLimit: 1024,
},
css: {
modules: {
generateScopedName: '[name]__[local]___[hash:base64:5]',
hashPrefix: 'prefix',
}
},
plugins: createVitePlugins(viteEnv, isBuild),
}
}