runtipi/esbuild.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-02-17 17:39:18 +00:00
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/no-var-requires */
const esbuild = require('esbuild');
const { spawn } = require('child_process');
const pkg = require('./package.json');
const isDev = process.argv[2] !== 'build';
process.env.NODE_ENV = isDev ? 'development' : 'production';
let server;
const onRebuild = () => {
if (isDev) {
if (server) server.kill('SIGINT');
server = spawn('node', ['dist/index.js'], { stdio: [0, 1, 2] });
} else {
spawn('pnpm', ['next', 'build'], { stdio: [0, 1, 2] });
2023-02-17 17:39:18 +00:00
}
};
2023-05-21 05:57:57 +00:00
const included = ['express', 'pg', '@runtipi/postgres-migrations', 'connect-redis', 'express-session', 'drizzle-orm'];
2023-02-17 17:39:18 +00:00
const excluded = ['pg-native', '*required-server-files.json'];
const external = Object.keys(pkg.dependencies || {}).filter((dep) => !included.includes(dep));
external.push(...excluded);
esbuild
.build({
entryPoints: ['src/server/index.ts'],
external,
define: { 'process.env.NODE_ENV': `"${process.env.NODE_ENV}"` },
platform: 'node',
2023-05-21 06:25:26 +00:00
target: 'node18',
2023-02-17 17:39:18 +00:00
outfile: 'dist/index.js',
tsconfig: 'tsconfig.json',
bundle: true,
2023-05-21 06:25:26 +00:00
minify: true,
2023-02-17 17:39:18 +00:00
sourcemap: isDev,
watch: false,
2023-02-17 17:39:18 +00:00
})
.finally(onRebuild);