From 9f49e743c62ea71f83f9749e1797698fddfd402e Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Mon, 15 Jul 2024 14:26:52 -0400 Subject: [PATCH 1/3] compile preace src instead of minified dist --- apps/dashboard/esbuild.config.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/esbuild.config.js b/apps/dashboard/esbuild.config.js index 92ecabe0da..bbfc6fce81 100644 --- a/apps/dashboard/esbuild.config.js +++ b/apps/dashboard/esbuild.config.js @@ -37,6 +37,22 @@ const prepPlugin = { }, } + +const preactSrcResolvePlugin = { + name: 'preactSrcResolve', + setup(build) { + // Redirect all paths starting with "images/" to "./public/images/" + build.onResolve({ filter: /preact/ }, args => { + const basePath = `${__dirname}/node_modules/preact`; + if (args.path == 'preact') { + return { path: `${basePath}/src/index.js` } + } else if(args.path == 'preact/hooks') { + return { path: `${basePath}/hooks/src/index.js` } + } + }) + }, +} + esbuild.build({ entryPoints: entryPoints, bundle: true, @@ -44,7 +60,7 @@ esbuild.build({ format: 'esm', outdir: buildDir, external: ['fs'], - plugins: [prepPlugin], + plugins: [prepPlugin, preactSrcResolvePlugin], minify: process.env.RAILS_ENV == 'production' ? true : false, }).catch((e) => console.error(e.message)); From 96ea3ff799971076752697f710a3be1e6388eff2 Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Thu, 25 Jul 2024 11:27:03 -0400 Subject: [PATCH 2/3] compile exifr source as well --- apps/dashboard/esbuild.config.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/apps/dashboard/esbuild.config.js b/apps/dashboard/esbuild.config.js index bbfc6fce81..891e8364a1 100644 --- a/apps/dashboard/esbuild.config.js +++ b/apps/dashboard/esbuild.config.js @@ -37,17 +37,24 @@ const prepPlugin = { }, } - -const preactSrcResolvePlugin = { - name: 'preactSrcResolve', +// don't package minified javascript +const minifiedSrcResolvePlugin = { + name: 'minifiedSrcResolvePlugin', setup(build) { // Redirect all paths starting with "images/" to "./public/images/" - build.onResolve({ filter: /preact/ }, args => { - const basePath = `${__dirname}/node_modules/preact`; - if (args.path == 'preact') { - return { path: `${basePath}/src/index.js` } - } else if(args.path == 'preact/hooks') { - return { path: `${basePath}/hooks/src/index.js` } + 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 } + } } }) }, @@ -60,7 +67,7 @@ esbuild.build({ format: 'esm', outdir: buildDir, external: ['fs'], - plugins: [prepPlugin, preactSrcResolvePlugin], + plugins: [prepPlugin, minifiedSrcResolvePlugin], minify: process.env.RAILS_ENV == 'production' ? true : false, }).catch((e) => console.error(e.message)); From a0f99b225458e2678746bba69da655372a8c049d Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Thu, 25 Jul 2024 12:17:14 -0400 Subject: [PATCH 3/3] update this comment a bit --- apps/dashboard/esbuild.config.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/dashboard/esbuild.config.js b/apps/dashboard/esbuild.config.js index 891e8364a1..958ea33e6c 100644 --- a/apps/dashboard/esbuild.config.js +++ b/apps/dashboard/esbuild.config.js @@ -37,12 +37,17 @@ const prepPlugin = { }, } -// don't package minified javascript +// 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) { - // Redirect all paths starting with "images/" to "./public/images/" - build.onResolve({ filter: /preact|exifr.*/ }, args => { + + build.onResolve({ filter: /preact|exifr.*/ }, args => { const preactBase = `${__dirname}/node_modules/preact`; const lookup = {