Upgrading Webpack 4 to 5
·
1 min read
·
189
Words
·
-Views
-Comments
It’s been about five months since Webpack 5 was released, and most of the ecosystem plugins are ready. With some spare time, I started the project upgrade.
Key Changes in Webpack 5
- Improved persistent caching for faster builds
- Better tree-shaking, reducing bundle size to some extent
- Several breaking changes to prepare for future evolution
In short, Webpack is a build tool and won’t affect the runtime functionality of your bundled JS. It’s worth upgrading.
Upgrade Steps
For full details, refer to the official docs. Here are the important steps:
Update Webpack and plugins to the latest versions
Recommend using
yarn upgrade-interactive
to select and update in bulk—more efficient.Adjust some settings
- HtmlWebpackPlugin: the
chunksSortMode
option changed; set it toauto
or similar webpack-merge
:merge
is no longer the default export- CLI: use
webpack-cli serve
instead of thewebpack-dev-server
command
- HtmlWebpackPlugin: the
If your frontend code depends on Node-specific packages, either remove the dependency or install and configure browser-ready alternatives.
- For example, my project used
content-disposition
. I rewrote it with browser JS instead.
- For example, my project used
Final Thoughts
- The upgrade is fairly straightforward with only a handful of changes, though there are a few gotchas.