-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
104 lines (91 loc) · 2.63 KB
/
vite.config.ts
File metadata and controls
104 lines (91 loc) · 2.63 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import type { PluginOption } from 'vite';
import { defineConfig, loadEnv } from 'vite';
import path from 'path';
import dao3cfg from './dao3.config';
import { ArenaUpdateScript } from 'vite-plugin-arenapro-script';
import checker from 'vite-plugin-checker';
import tsconfigPaths from 'vite-tsconfig-paths';
import dts from 'vite-plugin-dts';
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd());
const buildTarget =
(env.VITE_BUILD_TARGET as 'client' | 'server') || 'server';
const shouldUpload = env.VITE_UPDATE_FILE === 'true';
const currentBundleName = env.VITE_CURRENT_FILE;
const isClient = buildTarget === 'client';
const srcRoot = isClient ? 'client' : 'server'; // 请勿修改
const outDir = isClient ? 'dist/client' : 'dist/server';
const isDebugMode = mode === 'debug';
const isLintMode = mode === 'debug' || mode === 'production';
const isUploadMode = shouldUpload && !isDebugMode;
// 从 bundles 生成 rollup 多入口配置
const inputEntries: Record<string, string> = {};
for (const [bundleName, bundle] of Object.entries(dao3cfg.bundles)) {
if (currentBundleName && bundleName !== currentBundleName) {
continue;
}
if (bundle.enable === false) {
continue;
}
const side = bundle[buildTarget];
if (!side?.entry) {
continue;
}
inputEntries[bundleName] = path.resolve(`${srcRoot}/src/`, side.entry);
}
// 根据当前模式动态组装 Vite 插件
const plugins: PluginOption[] = [];
if (isLintMode) {
plugins.push(
checker({
typescript: {
tsconfigPath: `${srcRoot}/tsconfig.json`,
},
eslint: {
lintCommand: `eslint "${srcRoot}/src/**/*.{ts,tsx,js,cjs,mjs,jsx}"`,
},
})
);
}
if (isUploadMode) {
plugins.push(
ArenaUpdateScript({
outDir,
target: buildTarget,
env,
})
);
}
plugins.push(
tsconfigPaths({
root: srcRoot,
})
);
plugins.push(
dts({
tsconfigPath: `${srcRoot}/tsconfig.json`,
include: [`${srcRoot}/src`],
outDir: 'dist',
})
);
return {
plugins,
build: {
outDir,
emptyOutDir: true,
minify: mode === 'debug' || mode === 'development' ? false : 'esbuild',
sourcemap: mode === 'debug',
target: isClient ? 'esnext' : 'node16',
rollupOptions: {
input: inputEntries,
preserveEntrySignatures: 'strict',
external: ['react'],
output: {
format: isClient ? 'esm' : 'cjs',
entryFileNames: `[name].js`,
chunkFileNames: `[name].chunk.js`,
},
},
},
};
});