generated from NnsDAO-tech/FE-template-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
77 lines (74 loc) · 2.21 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
import react from '@vitejs/plugin-react';
import { readFileSync, writeFileSync } from 'fs';
import * as path from 'path';
import { defineConfig, loadEnv } from 'vite';
export default defineConfig(({ command, mode }) => {
const isProdCanister = mode === 'prod';
const env = loadEnv(isProdCanister ? 'prod' : 'developement', path.resolve('env'), '');
console.log('command,mode', command, mode);
// rewrite prod canister_ids
const canisterJsonPath = path.resolve('canister_ids.json');
const canisterJson = JSON.parse(readFileSync(canisterJsonPath).toString());
canisterJson.assets.ic = env.__APP__canister_id;
writeFileSync(canisterJsonPath, JSON.stringify(canisterJson));
return {
publicDir: 'src/public',
envDir: 'env',
envPrefix: ['VITE_', '__APP__'],
plugins: [
react(),
// visualizer({
// open: true,
// gzipSize: true,
// brotliSize: true,
// })
],
resolve: {
alias: {
// './runtimeConfig': './runtimeConfig.browser',
// Here we tell Vite the "fake" modules that we want to define
'@': path.resolve(__dirname, './src'),
'@common': path.resolve(__dirname, './src/common'),
'@idlFactory': path.resolve(__dirname, './src/idlFactory'),
},
},
build: {
outDir: 'dist',
cssCodeSplit: true,
chunkSizeWarningLimit: 500,
minify: 'terser',
terserOptions: {
compress: {
drop_console: isProdCanister,
drop_debugger: isProdCanister,
},
},
assetsDir: 'assets',
rollupOptions: {
output: {
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: 'assets/[ext]/[name]-[hash][extname]',
},
},
},
server: {
fs: {
strict: false,
},
port: 3000,
// proxy: {
// '/public/file': 'http://localhost:3003',
// '/public/': {
// target: 'http://localhost:3003',
// changeOrigin: true,
// // rewrite: path => path.replace(/^api\//, '/api/v2/canister'),
// },
// },
},
define: {
// dfx rely on this
'process.env': {},
},
};
});