Skip to content

Commit

Permalink
More esbuild fixes (#5618)
Browse files Browse the repository at this point in the history
  • Loading branch information
farhatahmad authored Dec 13, 2023
1 parent d999754 commit 02f76f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 16 additions & 10 deletions esbuild.dev.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 02f76f6

Please sign in to comment.