Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement min bundles #8599

Merged
merged 4 commits into from Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/bundlers/experimental/src/ExperimentalBundler.js
Expand Up @@ -949,7 +949,7 @@ function createIdealGraph(
}

// Create shared bundles for splittable bundles.
if (reachable.length > 0) {
if (reachable.length >= config.minBundles) {
let sourceBundles = reachable.map(a => nullthrows(bundles.get(a.id)));
let key = reachable.map(a => a.id).join(',');
let bundleId = bundles.get(key);
Expand Down Expand Up @@ -998,6 +998,15 @@ function createIdealGraph(
value: bundle,
type: 'bundle',
});
} else if (reachable.length < config.minBundles) {
for (let root of reachable) {
let bundle = nullthrows(
bundleGraph.getNode(nullthrows(bundles.get(root.id))),
);
invariant(bundle !== 'root');
bundle.assets.add(asset);
bundle.size += asset.stats.size;
}
}
}
// Step Merge Share Bundles: Merge any shared bundles under the minimum bundle size back into
Expand Down
49 changes: 48 additions & 1 deletion packages/core/integration-tests/test/bundler.js
Expand Up @@ -3,6 +3,53 @@ import assert from 'assert';
import {bundle, assertBundles, findAsset} from '@parcel/test-utils';

describe('bundler', function () {
it('should not create a shared bundle from an asset if that asset is shared by less than minBundles bundles', async function () {
let b = await bundle(
path.join(__dirname, 'integration/min-bundles/index.js'),
{
mode: 'production',
defaultTargetOptions: {
shouldScopeHoist: false,
},
},
);

assertBundles(b, [
{
name: 'index.js',
assets: [
'index.js',
'bundle-url.js',
'cacheLoader.js',
'css-loader.js',
'esmodule-helpers.js',
'js-loader.js',
'bundle-manifest.js',
],
},
{
// a and b are shared between only 2 bundles so they are kept in each bundle
assets: ['bar.js', 'a.js', 'b.js'],
},
{
assets: ['buzz.js'],
},
{
assets: ['a.js', 'b.js', 'foo.js'],
},
{
// c is shared between 3 different bundles, so it stays
assets: ['c.js'],
},
{
assets: ['styles.css'],
},
{
assets: ['local.html'],
},
]);
});

it('should remove reused bundle (over shared bundles based on size) if the bundlegroup hit the parallel request limit', async function () {
if (process.env.PARCEL_TEST_EXPERIMENTAL_BUNDLER) {
let b = await bundle(
Expand Down Expand Up @@ -53,7 +100,7 @@ describe('bundler', function () {
}
});

//This test case is the sdame as previous except we remove the shared bundle since it is smaller
//This test case is the same as previous except we remove the shared bundle since it is smaller
it('should remove shared bundle (over reused bundles based on size) if the bundlegroup hit the parallel request limit', async function () {
let b = await bundle(
path.join(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,7 @@
import a from './a';
import b from './b';
import styles from './styles.css';
import html from './local.html';
import c from './c';

export default 4;
@@ -0,0 +1 @@
import c from './c';

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,5 @@
import a from './a';
import b from './b';
import c from './c';

export default a;
@@ -0,0 +1,5 @@
import('./foo');
import('./bar');
import('./buzz');

export default 1;
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body>
Hello World
</body>
</html>
@@ -0,0 +1,7 @@
{
"@parcel/bundler-default": {
"minBundles": 3,
"minBundleSize": 200,
"maxParallelRequests":3
}
}
@@ -0,0 +1 @@
p.groove {outline-style: groove;}
Empty file.