Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do incremental builds with Webpack, across each invocation from the command line?

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.

like image 404
trusktr Avatar asked Mar 08 '17 18:03

trusktr


1 Answers

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

like image 52
Mugen Avatar answered Sep 19 '22 13:09

Mugen