-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
69 lines (64 loc) · 2.03 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
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react-swc';
import fs from 'fs-extra';
import path from 'path';
const symlink = (src, dest, type = 'dir') => {
const destFull = path.resolve(__dirname, dest);
if (!fs.existsSync(src)) {
console.log(
`Symlink source ${src} does not exist. Please set the REACT_CORE environment variable.`,
src
);
process.exit(1);
}
if (fs.existsSync(destFull)) {
fs.unlinkSync(destFull);
}
console.log(`Symlinking ${src} to ${destFull}`);
fs.symlinkSync(src, destFull, type);
};
const copyDir = (src, dest) => {
const sourceDir = path.resolve(__dirname, src);
const destinationDir = path.resolve(__dirname, dest);
fs.copySync(sourceDir, destinationDir, { overwrite: true });
};
// https://vitejs.dev/config/
export default defineConfig(({ mode, command }) => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
const reactShared = process.env.REACT_SHARED;
const s3Name = process.env.VITE_S3_NAME;
console.log('React shared:', reactShared);
console.log('S3 name:', s3Name);
return {
resolve: {
preserveSymlinks: true,
alias: {
'@': path.resolve(__dirname, './src'),
},
},
plugins: [
react(),
{
name: 'build-script',
buildStart() {
if (command === 'serve' || command === 'build') {
symlink(`${reactShared}`, './src/shared');
}
},
},
],
base: mode === 'production' ? `https://cdn.bighelp.ai/${s3Name}/` : '/',
server: {
port: 5173,
host: '0.0.0.0',
strictPort: true,
hmr: {
port: 5173,
},
fs: {
strict: false, // Allow serving files outside root
},
allowedHosts: ['frontend'],
},
};
});