Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an esbuild plugin for minified dependencies #3693

Merged
merged 4 commits into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion apps/dashboard/esbuild.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,42 @@ const prepPlugin = {
},
}

// We can run into conflicts if we use the minified
// version of some dependencies. So this plugin ensures
// that we compile the source code of a given dependency
// instead of the minified version.
//
// See https://github.com/OSC/ondemand/issues/3688 for more information.
const minifiedSrcResolvePlugin = {
name: 'minifiedSrcResolvePlugin',
setup(build) {

build.onResolve({ filter: /preact|exifr.*/ }, args => {

const preactBase = `${__dirname}/node_modules/preact`;
const lookup = {
'preact': `${preactBase}/src/index.js`,
'preact/hooks': `${preactBase}/hooks/src/index.js`,
'exifr/dist/mini.esm.mjs': `${__dirname}/node_modules/exifr/src/bundles/mini.mjs`,
}

for (const [key, value] of Object.entries(lookup)) {
if(args.path == key) {
return { path: value }
}
}
})
},
}

esbuild.build({
entryPoints: entryPoints,
bundle: true,
sourcemap: true,
format: 'esm',
outdir: buildDir,
external: ['fs'],
plugins: [prepPlugin],
plugins: [prepPlugin, minifiedSrcResolvePlugin],
minify: process.env.RAILS_ENV == 'production' ? true : false,
}).catch((e) => console.error(e.message));

Loading