When I run webpack
from command line, it just builds everything from scratch. How can we make Webpack do incremental builds across invocations of webpack
CLI, so that it parses and transpiles only files that have changed?
I'd like for this to work across each invocation of webpack
without a long-running process.
webpack --watch
and webpack-dev-server
are not options because they stay running, which I don't want.
For example, I want to run webpack
and it will exit, then the next time I run webpack
I would like it to be smart and not rebuild everything all over, just rebuild changed files.
Not incremental per-se, but webpack 5 introduced build cache: https://webpack.js.org/configuration/cache/ (see also related issue https://github.com/webpack/webpack/issues/6527)
Just add the following to webpack.config.js
:
module.exports = {
// ...
cache: {
type: 'filesystem'
},
};
Running a small benchmark on my application, build time with cache is cut by about 55-80%
Note however this feature is not recommended for CI use at the moment. See for example https://github.com/webpack/webpack/issues/13291
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With