-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathvite.config.mts
65 lines (60 loc) · 1.69 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
55
56
57
58
59
60
61
62
63
64
65
import module from "module"
import { type AliasOptions, type TerserOptions, defineConfig } from "vite"
import babel from "vite-plugin-babel"
import terserRc from "./.terserrc.mjs"
import babelConfig from "./babel.config.mts"
const viteConfig = defineConfig((configEnv) => {
const isLegacy = configEnv.mode.includes("legacy")
const plugins = []
if (isLegacy) {
plugins.push(
babel({
babelConfig,
}),
)
}
let aliasOpts: AliasOptions = {}
if (isLegacy) {
aliasOpts = {
...aliasOpts,
"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",
crypto: "./src/utils/compat/crypto/index.ts",
}
}
const isLibrary = configEnv.mode.includes("library")
return {
build: {
ssr: isLibrary
? "./src/lib.ts"
: "./src/setup-cpp.ts",
outDir: isLibrary ? "./dist/library" : isLegacy ? "./dist/legacy" : "./dist/modern",
target: isLegacy ? "node12" : "node20",
minify: process.env.NODE_ENV === "production" ? "terser" : false,
terserOptions: terserRc as TerserOptions,
sourcemap: true,
rollupOptions: {
output: {
format: isLegacy
? "cjs"
: "es",
},
},
emptyOutDir: false,
},
resolve: {
alias: aliasOpts,
},
ssr: {
target: "node",
noExternal: true,
external: [...module.builtinModules],
},
plugins,
}
})
export default viteConfig