diff --git a/apps/dashboard/esbuild.config.js b/apps/dashboard/esbuild.config.js index 92ecabe0da..958ea33e6c 100644 --- a/apps/dashboard/esbuild.config.js +++ b/apps/dashboard/esbuild.config.js @@ -37,6 +37,34 @@ 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, @@ -44,7 +72,7 @@ esbuild.build({ 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));