Skip to content

Commit 6413db9

Browse files
committed
Rewrite server build
1 parent 5bd8f6d commit 6413db9

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

.eslintrc.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
'plugin:react-hooks/recommended',
99
'plugin:css-modules/recommended',
1010
],
11-
ignorePatterns: ['dist', '.eslintrc.cjs', 'puppeteer.config.cjs'],
11+
ignorePatterns: ['dist', '*.cjs', '*.mjs', '*.js'],
1212
parser: '@typescript-eslint/parser',
1313
plugins: ['@typescript-eslint', 'react', 'react-refresh', 'css-modules'],
1414
rules: {

common/src/server/startServer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export const startServer = ({ envKeys, port, initApp }: Props) => {
2222

2323
const httpTerminator = createHttpTerminator({ server });
2424

25-
const shutdown = () => {
26-
console.log('Server shutting down');
25+
const shutdown = (signal: string) => {
26+
console.log(`Received ${signal} - Server shutting down`);
2727
httpTerminator.terminate().then(() => {
2828
server.close(() => {
2929
console.log('Shutdown complete!');

xp-archive/server/build.mjs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { build, context } from 'esbuild';
2+
3+
const isWatchMode = process.env.WATCH === 'true';
4+
5+
const options = {
6+
entryPoints: ['src/server.ts'],
7+
outfile: 'dist/server/server.cjs',
8+
bundle: true,
9+
platform: 'node',
10+
packages: 'external',
11+
};
12+
13+
if (isWatchMode) {
14+
console.log('Building in watch mode');
15+
await context(options).then((buildContext) => buildContext.watch());
16+
} else {
17+
console.log('Building in production mode');
18+
await build(options);
19+
}

xp-archive/server/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"private": true,
55
"type": "module",
66
"scripts": {
7-
"build": "esbuild src/server.ts --bundle --platform=node --packages=external --outfile=dist/server/server.cjs",
7+
"build": "node build.mjs",
8+
"build-and-watch": "WATCH=true node build.mjs",
89
"start": "node -r dotenv/config ./dist/server/server.cjs dotenv_config_path=../.env",
910
"nodemon-start": "nodemon -r dotenv/config -w ./dist/server -w ../.env ./dist/server/server.cjs dotenv_config_path=../.env",
10-
"dev": "npm run build && concurrently \"npm run build -- --watch\" \"npm run nodemon-start\""
11+
"dev": "concurrently \"npm run build-and-watch\" \"npm run nodemon-start\" --kill-others"
1112
},
1213
"dependencies": {
1314
"compression": "1.7.4",

0 commit comments

Comments
 (0)