Skip to content

Commit

Permalink
make sure to pass SSR page to WCC script deps
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Oct 22, 2022
1 parent 87aead0 commit af27313
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/cli/src/lifecycles/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ async function optimizePage(compilation, contents, route, outputPath, outputDir)
}

async function preRenderCompilationWorker(compilation, workerPrerender) {
const pages = compilation.graph.filter(page => !page.isSSR);
const pages = compilation.graph.filter(page => !page.isSSR || (page.isSSR && page.data.static) || (page.isSSR && compilation.config.prerender));
const outputDir = compilation.context.scratchDir;
const { pagesDir, userWorkspace } = compilation.context;

console.info('pages to generate', `\n ${pages.map(page => page.route).join('\n ')}`);

Expand All @@ -80,13 +81,14 @@ async function preRenderCompilationWorker(compilation, workerPrerender) {
style: true
});

const headScripts = root.querySelectorAll('script')
const templateScripts = root.querySelectorAll('script')
.filter(script => {
return script.getAttribute('type') === 'module'
&& script.getAttribute('src') && script.getAttribute('src').indexOf('http') < 0;
}).map(script => {
return pathToFileURL(path.join(compilation.context.userWorkspace, script.getAttribute('src').replace(/\.\.\//g, '').replace('./', '')));
return pathToFileURL(path.join(userWorkspace, script.getAttribute('src').replace(/\.\.\//g, '').replace('./', '')));
});
const pageScript = page.isSSR ? [pathToFileURL(path.join(pagesDir, page.filename))] : [];

await new Promise((resolve, reject) => {
const worker = new Worker(workerPrerender.workerUrl, {
Expand All @@ -96,7 +98,10 @@ async function preRenderCompilationWorker(compilation, workerPrerender) {
route,
prerender: true,
htmlContents: html,
scripts: JSON.stringify(headScripts)
scripts: JSON.stringify([
...pageScript,
...templateScripts
])
}
});
worker.on('message', (result) => {
Expand Down

0 comments on commit af27313

Please sign in to comment.