From 2c12fec1e693df3c610c6777c9c446cbf808f218 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Tue, 25 Apr 2023 03:54:49 -0500 Subject: [PATCH] Fix scripts not loading from the production ready build PR (#183) Follow-up to https://github.com/matrix-org/matrix-public-archive/pull/175 --- build-scripts/vite.config.js | 29 +++++++++++++------ server/hydrogen-render/render-page-html.js | 2 +- .../get-dependencies-for-entry-point-name.js | 15 ++++++---- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/build-scripts/vite.config.js b/build-scripts/vite.config.js index 7f5b964..29d781c 100644 --- a/build-scripts/vite.config.js +++ b/build-scripts/vite.config.js @@ -20,11 +20,14 @@ module.exports = defineConfig({ // splitVendorChunkPlugin(), ], - //root: './', - //base: './', - // optimizeDeps: { - // include: ['matrix-public-archive-shared'], - // }, + optimizeDeps: { + include: [ + // This doesn't seem to be necessary for the this package to work (ref + // https://vitejs.dev/guide/dep-pre-bundling.html#monorepos-and-linked-dependencies) + // + //'matrix-public-archive-shared' + ], + }, resolve: { alias: { // The `file:` packages don't seem resolve correctly so let's add an alias as well @@ -72,9 +75,17 @@ module.exports = defineConfig({ // Copy things like the version files from `public/` to `dist/` copyPublicDir: true, - // Fix `Error: 'default' is not exported by ...` when importing CommonJS files, see - // https://github.com/vitejs/vite/issues/2679 and docs: - // https://vitejs.dev/guide/dep-pre-bundling.html#monorepos-and-linked-dependencies - commonjsOptions: { include: [/shared/] }, + commonjsOptions: { + include: [ + // Fix `Error: 'default' is not exported by ...` when importing CommonJS files, see + // https://github.com/vitejs/vite/issues/2679 and docs: + // https://vitejs.dev/guide/dep-pre-bundling.html#monorepos-and-linked-dependencies + /shared\//, + + // Make all of our `require()` CommonJS calls compatible in the ESM client build. + // See https://vitejs.dev/guide/dep-pre-bundling.html#monorepos-and-linked-dependencies + /node_modules/, + ], + }, }, }); diff --git a/server/hydrogen-render/render-page-html.js b/server/hydrogen-render/render-page-html.js index 3a3a731..6826119 100644 --- a/server/hydrogen-render/render-page-html.js +++ b/server/hydrogen-render/render-page-html.js @@ -88,7 +88,7 @@ if (atEventId) { ${scripts .map( (scriptUrl) => - `` + `` ) .join('\n')}