mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 23:00:30 +00:00
6e3e6ac102
Co-authored-by: Dimitri Mitropoulos <dimitrimitropoulos@gmail.com> Co-authored-by: David Marby <david@dmarby.se>
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import esbuild from 'esbuild';
|
|
import { builtinModules } from 'module';
|
|
import path from 'path';
|
|
|
|
import pkg from './package.json';
|
|
|
|
interface Options {
|
|
mode?: 'development' | 'production';
|
|
}
|
|
|
|
export default async function build(options: Options) {
|
|
const mode = options.mode || 'production';
|
|
const __DEV__ = mode !== 'production';
|
|
const PORT = pkg.dev['dev-server-port'];
|
|
|
|
const outdir = __DEV__
|
|
? path.join(__dirname, 'app')
|
|
: path.join(__dirname, 'build');
|
|
|
|
const env: Record<string, string> = __DEV__
|
|
? {
|
|
'process.env.APP_RENDER_URL': JSON.stringify(
|
|
`http://localhost:${PORT}/index.html`
|
|
),
|
|
'process.env.NODE_ENV': JSON.stringify('development'),
|
|
'process.env.INSOMNIA_ENV': JSON.stringify('development'),
|
|
'process.env.BUILD_DATE': JSON.stringify(new Date()),
|
|
}
|
|
: {
|
|
'process.env.NODE_ENV': JSON.stringify('production'),
|
|
'process.env.INSOMNIA_ENV': JSON.stringify('production'),
|
|
'process.env.BUILD_DATE': JSON.stringify(new Date()),
|
|
};
|
|
|
|
return esbuild.build({
|
|
entryPoints: ['./app/main.development.ts'],
|
|
outfile: path.join(outdir, 'main.min.js'),
|
|
bundle: true,
|
|
platform: 'node',
|
|
sourcemap: true,
|
|
format: 'cjs',
|
|
define: env,
|
|
external: [
|
|
'electron',
|
|
'@getinsomnia/node-libcurl',
|
|
...Object.keys(pkg.dependencies),
|
|
...Object.keys(builtinModules),
|
|
],
|
|
});
|
|
}
|
|
|
|
// Build if ran as a cli script
|
|
const isMain = require.main === module;
|
|
|
|
if (isMain) {
|
|
const mode =
|
|
process.env.NODE_ENV === 'development' ? 'development' : 'production';
|
|
build({ mode });
|
|
}
|