-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvite.config.js
More file actions
79 lines (76 loc) · 1.9 KB
/
vite.config.js
File metadata and controls
79 lines (76 loc) · 1.9 KB
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
import { fileURLToPath, URL } from 'url';
import { defineConfig } from 'vite';
import { resolve } from 'path';
import { tmpdir } from 'os';
import { devLogger } from '@meituan-nocode/vite-plugin-dev-logger';
import {
devHtmlTransformer,
prodHtmlTransformer,
} from '@meituan-nocode/vite-plugin-nocode-html-transformer';
import react from '@vitejs/plugin-react';
const CHAT_VARIABLE = process.env.CHAT_VARIABLE || '';
const PUBLIC_PATH = process.env.PUBLIC_PATH || '';
const isProdEnv = process.env.NODE_ENV === 'production';
const publicPath = (isProdEnv && CHAT_VARIABLE)
? PUBLIC_PATH + '/' + CHAT_VARIABLE
: PUBLIC_PATH + '/';
const outDir = (isProdEnv && CHAT_VARIABLE) ? 'build/' + CHAT_VARIABLE : 'build';
const plugins = isProdEnv
? CHAT_VARIABLE
? [react(), prodHtmlTransformer(CHAT_VARIABLE)]
: [react()]
: [
devLogger({
dirname: resolve(tmpdir(), '.nocode-dev-logs'),
maxFiles: '3d',
}),
react(),
devHtmlTransformer(CHAT_VARIABLE),
];
// https://vitejs.dev/config/
export default defineConfig({
server: {
host: '::',
port: '8080',
hmr: {
overlay: false,
},
proxy: {
'/bing-suggest': {
target: 'https://api.bing.com',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/bing-suggest/, ''),
},
},
},
plugins,
base: publicPath,
build: {
outDir,
rollupOptions: {
input: {
popup: resolve(__dirname, 'index.html'),
},
output: {
entryFileNames: 'assets/[name].js',
chunkFileNames: 'assets/[name].js',
assetFileNames: 'assets/[name].[ext]'
}
}
},
resolve: {
alias: [
{
find: '@',
replacement: fileURLToPath(new URL('./src', import.meta.url)),
},
{
find: 'lib',
replacement: resolve(__dirname, 'lib'),
},
],
},
define: {
global: 'globalThis',
},
});