Fix scripts not loading from the production ready build PR (#183)

Follow-up to https://github.com/matrix-org/matrix-public-archive/pull/175
This commit is contained in:
Eric Eastwood 2023-04-25 03:54:49 -05:00 committed by GitHub
parent 630e58fadc
commit 2c12fec1e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 15 deletions

View File

@ -20,11 +20,14 @@ module.exports = defineConfig({
// splitVendorChunkPlugin(), // splitVendorChunkPlugin(),
], ],
//root: './', optimizeDeps: {
//base: './', include: [
// optimizeDeps: { // This doesn't seem to be necessary for the this package to work (ref
// include: ['matrix-public-archive-shared'], // https://vitejs.dev/guide/dep-pre-bundling.html#monorepos-and-linked-dependencies)
// }, //
//'matrix-public-archive-shared'
],
},
resolve: { resolve: {
alias: { alias: {
// The `file:` packages don't seem resolve correctly so let's add an alias as well // 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/` // Copy things like the version files from `public/` to `dist/`
copyPublicDir: true, copyPublicDir: true,
// Fix `Error: 'default' is not exported by ...` when importing CommonJS files, see commonjsOptions: {
// https://github.com/vitejs/vite/issues/2679 and docs: include: [
// https://vitejs.dev/guide/dep-pre-bundling.html#monorepos-and-linked-dependencies // Fix `Error: 'default' is not exported by ...` when importing CommonJS files, see
commonjsOptions: { include: [/shared/] }, // 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/,
],
},
}, },
}); });

View File

@ -88,7 +88,7 @@ if (atEventId) {
${scripts ${scripts
.map( .map(
(scriptUrl) => (scriptUrl) =>
`<script type="text/javascript" src="${scriptUrl}" nonce="${pageOptions.cspNonce}"></script>` `<script type="module" src="${scriptUrl}" nonce="${pageOptions.cspNonce}"></script>`
) )
.join('\n')} .join('\n')}
<script type="text/javascript" nonce="${pageOptions.cspNonce}"> <script type="text/javascript" nonce="${pageOptions.cspNonce}">

View File

@ -10,6 +10,7 @@ function getManifest() {
if (_manifest) { if (_manifest) {
return _manifest; return _manifest;
} }
// We have to disable this because it's built via the Vite client build. // We have to disable this because it's built via the Vite client build.
// eslint-disable-next-line n/no-missing-require, n/no-unpublished-require // eslint-disable-next-line n/no-missing-require, n/no-unpublished-require
_manifest = require('../../dist/manifest.json'); _manifest = require('../../dist/manifest.json');
@ -33,16 +34,19 @@ function recurseManifestEntryName(entryName) {
const manifest = getManifest(); const manifest = getManifest();
const entry = manifest[entryName]; const entry = manifest[entryName];
const entryFilePath = path.join('/', entry.file);
// css // css
const styles = []; const styles = [];
// imports // imports
const scripts = []; const scripts = [entryFilePath];
// imports, dynamicImports // imports, dynamicImports
const preloadScripts = []; const preloadScripts = [entryFilePath];
for (const importName of entry.imports || []) { for (const importName of entry.imports || []) {
scripts.push(path.join('/', importName)); const importFilePath = path.join('/', manifest[importName].file);
preloadScripts.push(path.join('/', importName)); scripts.push(importFilePath);
preloadScripts.push(importFilePath);
const { const {
styles: moreStyles, styles: moreStyles,
@ -56,7 +60,8 @@ function recurseManifestEntryName(entryName) {
} }
for (const dynamicImportName of entry.dynamicImports || []) { for (const dynamicImportName of entry.dynamicImports || []) {
preloadScripts.push(path.join('/', dynamicImportName)); const dynamicImportFilePath = path.join('/', manifest[dynamicImportName].file);
preloadScripts.push(dynamicImportFilePath);
const { const {
styles: moreStyles, styles: moreStyles,