diff options
Diffstat (limited to 'config/esbuildConfig.js')
-rw-r--r-- | config/esbuildConfig.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/config/esbuildConfig.js b/config/esbuildConfig.js new file mode 100644 index 0000000..05386b1 --- /dev/null +++ b/config/esbuildConfig.js | |||
@@ -0,0 +1,42 @@ | |||
1 | import { banner } from './buildConstants.js'; | ||
2 | |||
3 | /** @type {string} */ | ||
4 | const mode = process.env.MODE || 'development'; | ||
5 | |||
6 | /** @type {boolean} */ | ||
7 | const isDevelopment = mode === 'development'; | ||
8 | |||
9 | /** @type {string} */ | ||
10 | const modeString = JSON.stringify(mode); | ||
11 | |||
12 | /** | ||
13 | * @param {import('esbuild').BuildOptions} config | ||
14 | * @param {Record<string, unknown>} [extraMetaEnvVars] | ||
15 | * @returns {import('esbuild').BuildOptions} | ||
16 | */ | ||
17 | export function getConfig(config, extraMetaEnvVars) { | ||
18 | return { | ||
19 | logLevel: 'info', | ||
20 | bundle: true, | ||
21 | treeShaking: !isDevelopment, | ||
22 | minify: !isDevelopment, | ||
23 | banner: { | ||
24 | js: banner, | ||
25 | }, | ||
26 | ...config, | ||
27 | sourcemap: isDevelopment ? (config.sourcemap || true) : false, | ||
28 | define: { | ||
29 | 'process.env.NODE_ENV': modeString, | ||
30 | 'process.env.MODE': modeString, | ||
31 | 'import.meta.env': JSON.stringify({ | ||
32 | DEV: isDevelopment, | ||
33 | MODE: mode, | ||
34 | PROD: !isDevelopment, | ||
35 | ...extraMetaEnvVars, | ||
36 | }), | ||
37 | }, | ||
38 | plugins: [ | ||
39 | ...(config.plugins || []), | ||
40 | ], | ||
41 | }; | ||
42 | } | ||