提交 | 用户 | age
|
173d40
|
1 |
import type { UserConfig } from 'vite'; |
V |
2 |
|
2f6253
|
3 |
import { resolve } from 'path'; |
陈 |
4 |
|
173d40
|
5 |
import { modifyVars } from './build/config/lessModifyVars'; |
V |
6 |
import { createProxy } from './build/vite/proxy'; |
|
7 |
import globbyTransform from './build/vite/plugin/context/transform'; |
dc42d4
|
8 |
import dynamicImportTransform from './build/vite/plugin/dynamicImport/index'; |
2f6253
|
9 |
|
173d40
|
10 |
import { isDevFn, loadEnv } from './build/utils'; |
2f6253
|
11 |
|
173d40
|
12 |
import { createRollupPlugin, createVitePlugins } from './build/vite/plugin'; |
V |
13 |
|
bb3b8f
|
14 |
const pkg = require('./package.json'); |
N |
15 |
|
173d40
|
16 |
const viteEnv = loadEnv(); |
V |
17 |
|
bb3b8f
|
18 |
const { |
N |
19 |
VITE_PORT, |
|
20 |
VITE_PUBLIC_PATH, |
|
21 |
VITE_PROXY, |
8a1bfd
|
22 |
VITE_DROP_CONSOLE, |
bb3b8f
|
23 |
// VITE_USE_CDN, |
173d40
|
24 |
} = viteEnv; |
2f6253
|
25 |
|
陈 |
26 |
function pathResolve(dir: string) { |
|
27 |
return resolve(__dirname, '.', dir); |
|
28 |
} |
|
29 |
|
|
30 |
const viteConfig: UserConfig = { |
e8aede
|
31 |
/** |
9ee0a5
|
32 |
* Entry. Use this to specify a js entry file in use cases where an |
V |
33 |
* `index.html` does not exist (e.g. serving vite assets from a different host) |
|
34 |
* @default 'index.html' |
|
35 |
*/ |
7bd0b8
|
36 |
// TODO build error |
4ff6b7
|
37 |
// entry: 'public/index.html', |
9ee0a5
|
38 |
/** |
2f1fbf
|
39 |
* port |
e8aede
|
40 |
* @default '3000' |
B |
41 |
*/ |
|
42 |
port: VITE_PORT, |
2f6253
|
43 |
/** |
陈 |
44 |
* @default 'localhost' |
|
45 |
*/ |
|
46 |
hostname: 'localhost', |
|
47 |
/** |
2f1fbf
|
48 |
* Run to open the browser automatically |
2f6253
|
49 |
* @default 'false' |
陈 |
50 |
*/ |
|
51 |
open: false, |
|
52 |
/** |
2f1fbf
|
53 |
* Set to `false` to disable minification, or specify the minifier to use. |
V |
54 |
* Available options are 'terser' or 'esbuild'. |
2f6253
|
55 |
* @default 'terser' |
陈 |
56 |
*/ |
66acb2
|
57 |
minify: isDevFn() ? 'esbuild' : 'terser', |
2f6253
|
58 |
/** |
2f1fbf
|
59 |
* Base public path when served in production. |
2f6253
|
60 |
* @default '/' |
陈 |
61 |
*/ |
e8aede
|
62 |
base: VITE_PUBLIC_PATH, |
2f6253
|
63 |
|
陈 |
64 |
/** |
2f1fbf
|
65 |
* Directory relative from `root` where build output will be placed. If the |
V |
66 |
* directory exists, it will be removed before the build. |
2f6253
|
67 |
* @default 'dist' |
陈 |
68 |
*/ |
|
69 |
outDir: 'dist', |
|
70 |
/** |
2f1fbf
|
71 |
* Whether to generate sourcemap |
V |
72 |
* @default false |
2f6253
|
73 |
*/ |
陈 |
74 |
sourcemap: false, |
|
75 |
/** |
2f1fbf
|
76 |
* Directory relative from `outDir` where the built js/css/image assets will |
V |
77 |
* be placed. |
2f6253
|
78 |
* @default '_assets' |
陈 |
79 |
*/ |
|
80 |
assetsDir: '_assets', |
|
81 |
/** |
2f1fbf
|
82 |
* Static asset files smaller than this number (in bytes) will be inlined as |
V |
83 |
* base64 strings. Default limit is `4096` (4kb). Set to `0` to disable. |
|
84 |
* @default 4096 |
2f6253
|
85 |
*/ |
陈 |
86 |
assetsInlineLimit: 4096, |
|
87 |
/** |
2f1fbf
|
88 |
* Transpile target for esbuild. |
8a1bfd
|
89 |
* @default 'es2020' |
2f6253
|
90 |
*/ |
8a1bfd
|
91 |
esbuildTarget: 'es2020', |
2f1fbf
|
92 |
/** |
V |
93 |
* Whether to log asset info to console |
|
94 |
* @default false |
|
95 |
*/ |
e8aede
|
96 |
silent: false, |
2f1fbf
|
97 |
/** |
V |
98 |
* Import alias. The entries can either be exact request -> request mappings |
|
99 |
* (exact, no wildcard syntax), or request path -> fs directory mappings. |
|
100 |
* When using directory mappings, the key **must start and end with a slash**. |
|
101 |
* ``` |
|
102 |
*/ |
2f6253
|
103 |
alias: { |
陈 |
104 |
'/@/': pathResolve('src'), |
8a1bfd
|
105 |
}, |
2f1fbf
|
106 |
// terser options |
a9c2a2
|
107 |
terserOptions: { |
8a1bfd
|
108 |
compress: { |
V |
109 |
drop_console: VITE_DROP_CONSOLE, |
|
110 |
}, |
2f6253
|
111 |
}, |
bb3b8f
|
112 |
define: { |
N |
113 |
__VERSION__: pkg.version, |
|
114 |
}, |
2f6253
|
115 |
cssPreprocessOptions: { |
陈 |
116 |
less: { |
|
117 |
modifyVars: modifyVars, |
|
118 |
javascriptEnabled: true, |
|
119 |
}, |
|
120 |
}, |
2f1fbf
|
121 |
// The package will be recompiled using rollup, and the new package compiled into the esm module specification will be put into node_modules/.vite_opt_cache |
2f6253
|
122 |
optimizeDeps: { |
4f6b65
|
123 |
include: ['echarts/map/js/china', 'ant-design-vue/es/locale/zh_CN', '@ant-design/icons-vue'], |
2f6253
|
124 |
}, |
8a1bfd
|
125 |
|
2f1fbf
|
126 |
// Local cross-domain proxy |
e8aede
|
127 |
proxy: createProxy(VITE_PROXY), |
173d40
|
128 |
plugins: createVitePlugins(viteEnv), |
2f6253
|
129 |
rollupInputOptions: { |
bb3b8f
|
130 |
// TODO |
N |
131 |
// external: VITE_USE_CDN ? externals : [], |
173d40
|
132 |
plugins: createRollupPlugin(), |
2f6253
|
133 |
}, |
陈 |
134 |
}; |
|
135 |
|
8a1bfd
|
136 |
export default { |
V |
137 |
...viteConfig, |
dc42d4
|
138 |
transforms: [globbyTransform(viteConfig), dynamicImportTransform(viteEnv)], |
8a1bfd
|
139 |
} as UserConfig; |