-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.js
56 lines (55 loc) · 1.58 KB
/
vite.config.js
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
import react from '@vitejs/plugin-react-swc';
import { defineConfig, loadEnv } from 'vite';
import { resolve } from 'path';
// https://cn.vitejs.dev/config/#using-environment-variables-in-config
export default defineConfig(({ command, mode }) => {
// 根据当前工作目录中的 `mode` 加载 .env 文件
// 设置第三个参数为 '' 来加载所有环境变量,而不管是否有 `VITE_` 前缀。
const env = loadEnv(mode, process.cwd(), '');
const apiUrl = env.API_URL || 'http://localhost:8600';
return {
plugins: [react()],
build: {
outDir: 'dist',
sourcemap: false,
},
resolve: {
alias: [
{ find: /^~/, replacement: '' },
{ find: '@', replacement: resolve(__dirname, 'src') },
],
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
},
server: {
proxy: {
'/api': {
target: apiUrl,
changeOrigin: true,
rewrite: (apiPath) => apiPath.replace(/^\/api/, ''),
},
},
},
/**
* [plugin:vite:css] Inline JavaScript is not enabled. Is it set in your options?
*
* Ref:
* https://blog.csdn.net/baobao_123456789/article/details/113986961
* https://stackoverflow.com/questions/46729091/enable-inline-javascript-in-less
*/
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
},
},
},
test: {
css: false,
include: ['src/**/*.test.ts'],
globals: true,
environment: 'jsdom',
setupFiles: 'src/setupTests.ts',
clearMocks: true,
},
};
});