-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
72 lines (66 loc) · 1.75 KB
/
Copy pathvite.config.js
File metadata and controls
72 lines (66 loc) · 1.75 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
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';
async function loadPlugins() {
const plugins = isProdEnv
? CHAT_VARIABLE
? [react(), prodHtmlTransformer(CHAT_VARIABLE)]
: [react()]
: [
devLogger({
dirname: resolve(tmpdir(), '.nocode-dev-logs'),
maxFiles: '3d',
}),
react(),
devHtmlTransformer(CHAT_VARIABLE),
];
if (process.env.NOCODE_COMPILER_PATH) {
const { componentCompiler } = await import(process.env.NOCODE_COMPILER_PATH);
plugins.push(componentCompiler());
}
return plugins;
}
// https://vitejs.dev/config/
export default defineConfig(async () => {
const plugins = await loadPlugins();
return {
server: {
host: '::',
port: '8080',
hmr: {
overlay: false,
},
},
plugins,
base: publicPath,
build: {
outDir,
},
resolve: {
alias: [
{
find: '@',
replacement: fileURLToPath(new URL('./src', import.meta.url)),
},
{
find: 'lib',
replacement: resolve(__dirname, 'lib'),
},
],
},
};
});