-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvite.config.mts
65 lines (61 loc) · 1.6 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 UserConfig, defineConfig } from "vite"
import babel from "vite-plugin-babel"
import babelConfig from "./babel.config.mts"
// Instead of using TARGET env variable, we'll use Vite's mode
export default defineConfig(async (configEnv) => {
const isLegacy = configEnv.mode.includes("legacy")
const plugins = isLegacy
? [
babel({
babelConfig,
}),
]
: []
if (process.env.BUILD_ANALYSIS === "true") {
const visualizer = (await import("rollup-plugin-visualizer")).visualizer
plugins.push(
visualizer({
sourcemap: true,
}),
)
}
return {
build: {
ssr: "./src/main.ts",
outDir: "./build",
target: isLegacy ? "node12" : "node20",
minify: process.env.NODE_ENV === "development" ? false : "esbuild",
sourcemap: true,
rollupOptions: {
output: {
format: isLegacy ? "cjs" : "es",
manualChunks: {
lib: ["./src/lib.ts"],
},
chunkFileNames: (chunkInfo) => {
if (chunkInfo.name === "lib") {
return isLegacy ? "lib.js" : "lib.mjs"
}
return chunkInfo
},
},
},
emptyOutDir: false,
},
resolve: {
alias: {
// unused dependency
"@aws-sdk/client-s3": "./src/deps/aws-sdk-client-s3.ts",
// deduplicate mkdirp via fs-extra
mkdirp: "./src/deps/mkdirp.ts",
},
},
ssr: {
target: "node",
noExternal: true,
external: module.builtinModules as string[],
},
plugins,
} as UserConfig
})