diff --git a/lib/client-bundle-plugin.js b/lib/client-bundle-plugin.js index 827f3ced..b798b4da 100644 --- a/lib/client-bundle-plugin.js +++ b/lib/client-bundle-plugin.js @@ -15,6 +15,7 @@ import rollup from 'rollup'; const prefix = 'client-bundle:'; const entryPathPlaceholder = 'CLIENT_BUNDLE_PLUGIN_ENTRY_PATH'; const importsPlaceholder = 'CLIENT_BUNDLE_PLUGIN_IMPORTS'; +const allSrcPlaceholder = 'CLIENT_BUNDLE_PLUGIN_ALL_SRC'; export function getDependencies(clientOutput, item) { const crawlDependencies = new Set([item.fileName]); @@ -70,6 +71,9 @@ export default function (inputOptions, outputOptions, resolveFileUrl) { `export const imports = import.meta.${ importsPlaceholder + exportCounter };`, + `export const allSrc = import.meta.${ + allSrcPlaceholder + exportCounter + };`, ].join('\n'); }, async buildEnd(error) { @@ -108,6 +112,8 @@ export default function (inputOptions, outputOptions, resolveFileUrl) { num = Number(property.slice(entryPathPlaceholder.length)); } else if (property.startsWith(importsPlaceholder)) { num = Number(property.slice(importsPlaceholder.length)); + } else if (property.startsWith(allSrcPlaceholder)) { + num = Number(property.slice(allSrcPlaceholder.length)); } else { // This isn't one of our placeholders. return; @@ -128,6 +134,12 @@ export default function (inputOptions, outputOptions, resolveFileUrl) { const dependencies = getDependencies(clientOutput, clientEntry); + if (property.startsWith(allSrcPlaceholder)) { + return JSON.stringify( + [clientEntry.code, ...dependencies.map((d) => d.code)].join(';'), + ); + } + return ( '[' + dependencies diff --git a/src/static-build/missing-types.d.ts b/src/static-build/missing-types.d.ts index 12b7cad7..5c48298c 100644 --- a/src/static-build/missing-types.d.ts +++ b/src/static-build/missing-types.d.ts @@ -17,6 +17,8 @@ declare module 'client-bundle:*' { const url: string; export default url; export const imports: string[]; + /** Source for this script and all its dependencies */ + export const allSrc: string; } declare module 'initial-css:' { diff --git a/src/static-build/pages/index/index.tsx b/src/static-build/pages/index/index.tsx index 8f433282..c2c4ca6f 100644 --- a/src/static-build/pages/index/index.tsx +++ b/src/static-build/pages/index/index.tsx @@ -14,7 +14,7 @@ import { h, FunctionalComponent } from 'preact'; import baseCss from 'css:./base.css'; import initialCss from 'initial-css:'; -import clientBundleURL, { imports } from 'client-bundle:client/initial-app'; +import { allSrc } from 'client-bundle:client/initial-app'; import favicon from 'url:static-build/assets/favicon.ico'; import { escapeStyleScriptContent } from 'static-build/utils'; import Intro from 'shared/initial-app/Intro'; @@ -46,15 +46,16 @@ const Index: FunctionalComponent = () => ( __html: escapeStyleScriptContent(initialCss), }} /> -