question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Initial vendor chunks not respecting minSize

See original GitHub issue

Bug report

What is the current behavior?

Changing minSIze to 520KB generates synchronous ( initial ) vendor chunk of size 517KB.

If the current behavior is a bug, please provide the steps to reproduce.

I have two entry points with async/sync modules.

// a.js
import { run } from "./app/app";
import ("lodash");
import "bootstrap";
import "./main.scss";
import { AlertService } from "./app/alert.service";
import { ComponentService } from "./app/component.service";
const alertService = new AlertService();
const componentService = new ComponentService();
run(alertService, componentService);
// b.js
import { run } from "./app/app";
import ("lodash");
import ("bootstrap");
import "./main.scss";
import { AlertService } from "./app/alert.service";
import { ComponentService } from "./app/component.service";
const alertService = new AlertService();
const componentService = new ComponentService();
run(alertService, componentService);

The optimization plugin config without custom minSize is as follows where everything generated as expected

  optimization: {
    minimize: false,
    splitChunks: {
      chunks: "initial",
      // minSize: 520000,
    }
  }

generated chunks with above config

4.0430a28c67c95515623d.bundle.js   509 KiB       4  [emitted] [immutable]  [big]  
5.177897857c70dc7eaa96.bundle.js   531 KiB    5, 6  [emitted] [immutable]  [big]  
6.507730afe61b6ceecf70.bundle.js   531 KiB       6  [emitted] [immutable]  [big]  
a.ac0e9c622ffd0aace615.bundle.js  10.2 KiB       1  [emitted] [immutable]         a
a~b.1fafc50267cf2e753b51.bundle.js   148 KiB       0  [emitted] [immutable]         a~b
b.b9218b218e06859b7b0d.bundle.js  18.5 KiB       2  [emitted] [immutable]         b
imgs/webpack.523e1b932381f19b26060571ccfc7a31.svg  2.29 KiB          [emitted] [immutable]         
index.html  1.77 KiB          [emitted]                     
vendors~a.50adedf6af3fbeb56ed3.bundle.js   517 KiB    3, 4  [emitted] [immutable]  [big]  vendors~a

If uncommented minSize from above config following is the generated output

3.4fe397947d6a74a38870.bundle.js   509 KiB       3  [emitted] [immutable]  [big]  
4.5289e4657b1f86d851f1.bundle.js   531 KiB    4, 5  [emitted] [immutable]  [big]  
5.ad452c25e6aa46a1cdff.bundle.js   531 KiB       5  [emitted] [immutable]  [big]  
a.974925a2f0898c477b9e.bundle.js   158 KiB       0  [emitted] [immutable]         a
b.2cd9e2bdb8245dd78851.bundle.js   165 KiB       1  [emitted] [immutable]         b
imgs/webpack.523e1b932381f19b26060571ccfc7a31.svg  2.29 KiB          [emitted] [immutable]         
index.html  1.72 KiB          [emitted]                     
vendors~a.e51176a01049374bf6f1.bundle.js   517 KiB    2, 3  [emitted] [immutable]  [big]  vendors~a

Note that a.bundle.js and b.bundle.js is increased as main.scss is not spitted out to separate chunk due to minSIze restriction. But its still creating vendor~a chunk even tho its size is 517kb.

If we set minSize to significantly increased number i.e 999999999 we get the expected output with no initial chunks

2.4d4ab8a0eebe11a6149c.bundle.js   509 KiB       2  [emitted] [immutable]  [big]  
3.434ee8f39d57e8f7dee7.bundle.js   531 KiB    3, 4  [emitted] [immutable]  [big]  
4.d890b35757aa13206d0e.bundle.js   531 KiB       4  [emitted] [immutable]  [big]  
a.16d5f9d877a088513a7d.bundle.js   674 KiB    0, 2  [emitted] [immutable]  [big]  a
b.062bc745c5f2e5e55948.bundle.js   165 KiB       1  [emitted] [immutable]         b
imgs/webpack.523e1b932381f19b26060571ccfc7a31.svg  2.29 KiB          [emitted] [immutable]         
index.html  1.66 KiB          [emitted]           

What is the expected behavior? When setting minSize to 520kb vendor~a chunk should not be generated as happening with main.scss, respecting minSize.

Other relevant information: webpack version: 4.44.2 Node.js version: 12.19.0 Operating System: ubuntu budgie Additional tools:

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sokracommented, Jan 7, 2021

Thanks. I found the problem. It’s a bug in webpack.

0reactions
sokracommented, Jan 8, 2021

Probably today

Read more comments on GitHub >

github_iconTop Results From Across the Web

optimization.splitChunks does not respect entry #7883 - GitHub
When using multiple entry points, specifying splitChunks to break out vendors has no way to organize by entry, so the compiled vendor files ......
Read more >
SplitChunksPlugin - webpack
Webpack will automatically split chunks based on these conditions: New chunk can be shared OR modules are from the node_modules folder.
Read more >
node.js - Webpack 4 - create vendor chunk - Stack Overflow
In order to reduce the vendor JS bundle size. We can split the node module packages into different bundle files.
Read more >
Demystifying Webpack 4 Split Chunks Plugin
Recently, we migrated one of our web apps to the Webpack 4, which decreases build time and reduces chunk size by using Split...
Read more >
Webpack v4 chunk splitting deep dive | Chris Claxton's Blog
This is determined by the splitChunks.minSize setting (default is 30000) sets a rule that says a chunk should not be created unless it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found