Skip to content

Commit

Permalink
partial fix for #5137
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jun 1, 2022
1 parent 6c9e72e commit ed36d49
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/kit/src/core/build/build_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function build_client(options) {
const entry = posixify(client_entry_file);
const entry_js = new Set();
const entry_css = new Set();
find_deps(entry, vite_manifest, entry_js, entry_css);
find_deps(entry, vite_manifest, entry_js, entry_css, false);

fs.writeFileSync(
`${client_out_dir}/version.json`,
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/build/build_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export async function build_server(options, client) {

const js = new Set();
const css = new Set();
find_deps(component, client.vite_manifest, js, css);
find_deps(component, client.vite_manifest, js, css, false);

const imports = [`import * as module from '../${vite_manifest[component].file}';`];

Expand Down
11 changes: 8 additions & 3 deletions packages/kit/src/core/build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,24 @@ export async function create_build(config) {
* @param {import('vite').Manifest} manifest
* @param {Set<string>} css
* @param {Set<string>} js
* @param {boolean} dynamic
*/
export function find_deps(file, manifest, js, css) {
export function find_deps(file, manifest, js, css, dynamic) {
const chunk = manifest[file];

if (js.has(chunk.file)) return;
js.add(chunk.file);
if (!dynamic) js.add(chunk.file);

if (chunk.css) {
chunk.css.forEach((file) => css.add(file));
}

if (chunk.imports) {
chunk.imports.forEach((file) => find_deps(file, manifest, js, css));
chunk.imports.forEach((file) => find_deps(file, manifest, js, css, dynamic));
}

if (chunk.dynamicImports) {
chunk.dynamicImports.forEach((file) => find_deps(file, manifest, js, css, true));
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/kit/src/core/dev/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ async function find_deps(vite, node, deps) {
if (node.ssrTransformResult.deps) {
node.ssrTransformResult.deps.forEach((url) => branches.push(add_by_url(url)));
}

if (node.ssrTransformResult.dynamicDeps) {
node.ssrTransformResult.dynamicDeps.forEach((url) => branches.push(add_by_url(url)));
}
} else {
node.importedModules.forEach((node) => branches.push(add(node)));
}
Expand Down

0 comments on commit ed36d49

Please sign in to comment.