2024-01-31 11:21:18 +00:00
|
|
|
import { build, type BuildOptions, context } from 'esbuild';
|
2022-05-25 13:58:28 +00:00
|
|
|
|
|
|
|
const isProd = Boolean(process.env.NODE_ENV === 'production');
|
2023-06-29 16:02:02 +00:00
|
|
|
const watch = Boolean(process.env.ESBUILD_WATCH);
|
2023-08-09 22:14:16 +00:00
|
|
|
const version = process.env.VERSION || 'dev';
|
2024-01-31 11:21:18 +00:00
|
|
|
const config: BuildOptions = {
|
2022-05-25 13:58:28 +00:00
|
|
|
outfile: './dist/index.js',
|
|
|
|
bundle: true,
|
|
|
|
platform: 'node',
|
|
|
|
minify: isProd,
|
2024-04-11 12:49:58 +00:00
|
|
|
target: 'node20',
|
2022-05-25 13:58:28 +00:00
|
|
|
sourcemap: true,
|
|
|
|
format: 'cjs',
|
2023-08-09 22:14:16 +00:00
|
|
|
tsconfig: 'tsconfig.json',
|
2022-05-25 13:58:28 +00:00
|
|
|
plugins: [
|
2024-04-11 12:49:58 +00:00
|
|
|
// taken from https://github.com/tjx666/awesome-vscode-extension-boilerplate/blob/main/scripts/esbuild.ts
|
|
|
|
{
|
|
|
|
name: 'umd2esm',
|
|
|
|
setup(build) {
|
|
|
|
build.onResolve({ filter: /^(vscode-.*|estree-walker|jsonc-parser)/ }, args => {
|
|
|
|
const pathUmdMay = require.resolve(args.path, {
|
|
|
|
paths: [args.resolveDir],
|
|
|
|
});
|
|
|
|
// Call twice the replace is to solve the problem of the path in Windows
|
|
|
|
const pathEsm = pathUmdMay
|
|
|
|
.replace('/umd/', '/esm/')
|
|
|
|
.replace('\\umd\\', '\\esm\\');
|
|
|
|
return { path: pathEsm };
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
2022-05-25 13:58:28 +00:00
|
|
|
],
|
|
|
|
define: {
|
|
|
|
'process.env.DEFAULT_APP_NAME': JSON.stringify(isProd ? 'Insomnia' : 'insomnia-app'),
|
2023-08-09 22:14:16 +00:00
|
|
|
'process.env.VERSION': JSON.stringify(isProd ? version : 'dev'),
|
2022-05-25 13:58:28 +00:00
|
|
|
'__DEV__': JSON.stringify(!isProd),
|
|
|
|
},
|
2024-04-11 12:49:58 +00:00
|
|
|
external: ['@getinsomnia/node-libcurl', 'insomnia-send-request', 'fsevents', 'mocha'],
|
2022-05-25 13:58:28 +00:00
|
|
|
entryPoints: ['./src/index.ts'],
|
2024-01-31 11:21:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (watch) {
|
|
|
|
async function watch() {
|
|
|
|
const ctx = await context(config);
|
|
|
|
await ctx.watch();
|
|
|
|
}
|
|
|
|
watch();
|
|
|
|
} else {
|
|
|
|
build(config);
|
|
|
|
}
|