What is the performance impact of using array configuration in webpack
I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.
Search for a command to run...
I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.
No comments yet. Be the first to comment.
In this series, I'll share tips about optimizing your webpack configuration.
In this article, I'll show a benchmark of build time with and without chunk splitting. Chunks Chunks are parts of the build that can be reused between different entry points. This is especially useful for the users of the multipage websites - as shar...
I’ve been working in programming for the last 16 years. Let’s see what changes I see in our industry that are enabled by generative AI. Rapid prototyping The last few months, I’ve been working on a set of WordPress plugins, related to event organizat...
Writing unit tests takes time and effort. Nonetheless, many teams insist on writing them anyway—that’s because of the benefits they bring to a project. Those benefits are mainly the following: fast feedback—unit tests speed up each iteration of twea...

Pure functions are the perfect case for unit testing. For a given input, we always expect the same output—there is no internal state involved. Let’s take a look at a few examples and some simple tests that check if the methods work as expected. Jasmi...

Let’s say you have a job interview in a few days. How should you prepare for it so that you can make an informed decision about joining the company, as well as make sure that your interests are taken care of? Prepare your questions An interview is a ...

Creating example projects is a common way of showing your skills to potential employers. Let’s take a look at what’s important to keep in mind when building personal projects with an eye toward impressing prospective employers. Simplicity Building ap...

Webpack has the feature of accepting an array of configuration objects instead of one object. Unfortunately, it comes with a performance penalty - in this article, I'll look at how serious the slow-down can get.
I'll have 10 files in the benchmark, src/a.js, src/b.js, etc. Each of the failed contains:
import $ from "jquery";
$(".a").html("a");
Where:
jquery makes the build size non-trivialThere are 2 configuration approaches to be compared.
Here there is 1 object, which defines multiple entry points:
module.exports = {
entry: {
a: "./src/a",
b: "./src/b",
...
},
};
The time output for the build is:
real 0m9,507s
user 0m29,622s
sys 0m0,438s
It tasks about 9.5s to run the build.
In an array configuration, we have multiple configuration objects returned together. It allows for greater flexibility:
module.exports = [
{
entry: {
a: "./src/a",
},
},
{
entry: {
b: "./src/b",
},
},
...
];
The time output:
real 0m14,622s
user 0m48,990s
sys 0m0,877s
It took 14.5s to build the same files, about 50% longer.
The difference becomes even starker when we introduce splitting. Splitting allows webpack to optimize & build only once parts that are used in many places. This optimization is done in the context of each configuration object - so if we use a configuration array, we won't see improvements.
b/webpack.object.js:
i: "./src/i",
j: "./src/j",
},
+ optimization: {
+ splitChunks: {
+ // include all types of chunks
+ chunks: "all",
+ },
+ },
};
Build times:
real 0m3,074s
user 0m5,724s
sys 0m0,161s
About 3s build time.
If we had more complex cases for each entry point, we could see some speed improvements, but there is no chance for this simplified example.
webpack.array.js
@@ -3,50 +3,110 @@ module.exports = [
entry: {
a: "./src/a",
},
+ optimization: {
+ splitChunks: {
+ // include all types of chunks
+ chunks: "all",
+ },
+ },
},
{
entry: {
b: "./src/b",
},
+ optimization: {
+ splitChunks: {
+ // include all types of chunks
+ chunks: "all",
+ },
+ },
},
...
time output:
real 0m14,904s
user 0m48,754s
sys 0m1,154s
The build took almost 15s, five times slower than with the object configuration.
In this article, we have seen a build time benchmark for 2 formats of webpack configuration. One can understand the array configuration as a shortcut to run multiple, unrelated builds - there will not be many optimizations done by wepback.