setup-cpp/vite.config.mts

55 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

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"
2024-09-04 16:27:11 +08:00
const isLegacy = process.env.TARGET === "legacy"
const viteConfig = defineConfig({
build: {
ssr: "./src/setup-cpp.ts",
2024-09-04 16:27:11 +08:00
outDir: isLegacy ? "./dist/legacy" : "./dist/modern",
target: isLegacy ? "node12" : "node20",
minify: "terser",
terserOptions: terserRc as TerserOptions,
sourcemap: true,
2024-09-04 16:27:11 +08:00
rollupOptions: {
output: {
format: isLegacy
? "cjs"
: "es",
},
},
2024-09-19 13:16:30 +08:00
emptyOutDir: process.env.NODE_ENV === "production",
2024-09-04 16:27:11 +08:00
},
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",
2024-09-04 16:27:11 +08:00
diagnostics_channel: "diagnostics_channel/index.js",
}
: {}),
},
},
ssr: {
target: "node",
noExternal: true,
external: module.builtinModules,
},
plugins: isLegacy
? [
babel({
babelConfig,
}),
]
: [],
})
export default viteConfig