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:
parent
630e58fadc
commit
2c12fec1e6
|
@ -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,
|
||||||
|
|
||||||
|
commonjsOptions: {
|
||||||
|
include: [
|
||||||
// Fix `Error: 'default' is not exported by ...` when importing CommonJS files, see
|
// Fix `Error: 'default' is not exported by ...` when importing CommonJS files, see
|
||||||
// https://github.com/vitejs/vite/issues/2679 and docs:
|
// https://github.com/vitejs/vite/issues/2679 and docs:
|
||||||
// https://vitejs.dev/guide/dep-pre-bundling.html#monorepos-and-linked-dependencies
|
// https://vitejs.dev/guide/dep-pre-bundling.html#monorepos-and-linked-dependencies
|
||||||
commonjsOptions: { include: [/shared/] },
|
/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/,
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -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}">
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue