From 02f76f6db879a11428bbd9b0e8129156810fa701 Mon Sep 17 00:00:00 2001 From: Ahmad Farhat Date: Wed, 13 Dec 2023 15:19:35 -0500 Subject: [PATCH] More esbuild fixes (#5618) --- esbuild.dev.mjs | 26 ++++++++++++++++---------- package.json | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/esbuild.dev.mjs b/esbuild.dev.mjs index 3ff7311405..ded76ccc13 100644 --- a/esbuild.dev.mjs +++ b/esbuild.dev.mjs @@ -3,7 +3,7 @@ import * as esbuild from 'esbuild'; // Fetch 'RELATIVE_URL_ROOT' ENV variable value while removing any trailing slashes. const relativeUrlRoot = (process.env.RELATIVE_URL_ROOT || '').replace(/\/*$/, ''); -await esbuild.build({ +esbuild.context({ entryPoints: ['app/javascript/main.jsx'], bundle: true, sourcemap: true, @@ -12,16 +12,22 @@ await esbuild.build({ '.png': 'dataurl', '.svg': 'text', }, - watch: { - onRebuild: (error, result) => { - if (error) console.error('watch build failed:', error); - else console.log('watch build succeeded:', result); - }, - }, define: { 'process.env.RELATIVE_URL_ROOT': `"${relativeUrlRoot}"`, 'process.env.OMNIAUTH_PATH': `"${relativeUrlRoot}/auth/openid_connect"`, // currently, only OIDC is implemented }, -}); - -console.log('watch build started'); +}).then(context => { + if (process.argv.includes("--watch")) { + // Enable watch mode + context.watch() + } else { + // Build once and exit if not in watch mode + context.rebuild().then(result => { + context.dispose() + }) + } + console.log('build succeeded'); +}).catch((e) => { + console.error('build failed:', e); + process.exit(1) +}) \ No newline at end of file diff --git a/package.json b/package.json index eace195343..c1d3ac1ac1 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "scripts": { "build": "node esbuild.mjs", "build:css": "sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules --style compressed", - "build:development": "node esbuild.dev.mjs", + "build:development": "node esbuild.dev.mjs --watch", "build:development:css": "sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules" }, "devDependencies": {