Skip to content

Commit

Permalink
Decrease bundle manifest size
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcompiles committed Aug 3, 2023
1 parent 1dbda59 commit 8e8233c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
15 changes: 9 additions & 6 deletions packages/runtimes/js/src/JSRuntime.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,27 +624,30 @@ function getRegisterCode(
entryBundle: NamedBundle,
bundleGraph: BundleGraph<NamedBundle>,
): string {
let idToName = [];
let mappings = [];
bundleGraph.traverseBundles((bundle, _, actions) => {
if (bundle.bundleBehavior === 'inline') {
return;
}

idToName.push([
// To make the manifest as small as possible all bundle key/values are
// serialised into a single array e.g. ['id', 'value', 'id2', 'value2'].
// `./helpers/bundle-manifest` accounts for this by iterating index by 2
mappings.push(
bundle.publicId,
relativeBundlePath(entryBundle, nullthrows(bundle), {
leadingDotSlash: false,
}),
]);
);

if (bundle !== entryBundle && isNewContext(bundle, bundleGraph)) {
for (let referenced of bundleGraph.getReferencedBundles(bundle)) {
idToName.push([
mappings.push(
referenced.publicId,
relativeBundlePath(entryBundle, nullthrows(referenced), {
leadingDotSlash: false,
}),
]);
);
}
// New contexts have their own manifests, so there's no need to continue.
actions.skipChildren();
Expand All @@ -658,7 +661,7 @@ function getRegisterCode(
: `require('./helpers/bundle-url').getBundleURL('${entryBundle.publicId}')`;

return `require('./helpers/bundle-manifest').register(${baseUrl},JSON.parse(${JSON.stringify(
JSON.stringify(idToName),
JSON.stringify(mappings),
)}));`;
}

Expand Down
9 changes: 6 additions & 3 deletions packages/runtimes/js/src/helpers/bundle-manifest.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
var mapping = new Map();

function register(baseUrl, pairs) {
for (var i = 0; i < pairs.length; i++) {
mapping.set(pairs[i][0], {baseUrl, path: pairs[i][1]});
function register(baseUrl, manifest) {
for (var i = 0; i < manifest.length - 1; i += 2) {
mapping.set(manifest[i], {
baseUrl: baseUrl,
path: manifest[i + 1],
});
}
}

Expand Down

0 comments on commit 8e8233c

Please sign in to comment.