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
|
import { banner } from './buildConstants.js';
/** @type {string} */
const mode = process.env.MODE || 'development';
/** @type {boolean} */
const isDevelopment = mode === 'development';
/** @type {string} */
const modeString = JSON.stringify(mode);
/**
* @param {import('esbuild').BuildOptions} config
* @param {Record<string, unknown>} [extraMetaEnvVars]
* @returns {import('esbuild').BuildOptions}
*/
export function getConfig(config, extraMetaEnvVars) {
return {
logLevel: 'info',
bundle: true,
treeShaking: !isDevelopment,
minify: !isDevelopment,
banner: {
js: banner,
},
...config,
sourcemap: isDevelopment ? (config.sourcemap || true) : false,
define: {
'process.env.NODE_ENV': modeString,
'process.env.MODE': modeString,
'import.meta.env': JSON.stringify({
DEV: isDevelopment,
MODE: mode,
PROD: !isDevelopment,
...extraMetaEnvVars,
}),
},
plugins: [
...(config.plugins || []),
],
};
}
|