-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
vite.config.mts
54 lines (51 loc) · 1.33 KB
/
vite.config.mts
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
import module from "module"
import { type TerserOptions, defineConfig } from "vite"
import babel from "vite-plugin-babel"
import terserRc from "./.terserrc.mjs"
import babelConfig from "./babel.config.mts"
const isLegacy = process.env.TARGET === "legacy"
const viteConfig = defineConfig({
build: {
ssr: "./src/setup-cpp.ts",
outDir: isLegacy ? "./dist/legacy" : "./dist/modern",
target: isLegacy ? "node12" : "node20",
minify: "terser",
terserOptions: terserRc as TerserOptions,
sourcemap: true,
rollupOptions: {
output: {
format: isLegacy
? "cjs"
: "es",
},
},
emptyOutDir: process.env.NODE_ENV === "production",
},
resolve: {
alias: {
...(isLegacy
? {
"fs/promises": "./src/utils/compat/fs/promises.ts",
"stream/promises": "./src/utils/compat/stream/promises.ts",
"stream/web": "web-streams-polyfill/dist/ponyfill.mjs",
"util/types": "util.types/index.js",
"timers/promises": "timers-browserify",
diagnostics_channel: "diagnostics_channel/index.js",
}
: {}),
},
},
ssr: {
target: "node",
noExternal: true,
external: module.builtinModules,
},
plugins: isLegacy
? [
babel({
babelConfig,
}),
]
: [],
})
export default viteConfig