2

I have a webpack project, which is built together with another components by SBT. The webpack production build compiles the src provides me with a dist folder, which is built from the src folder, and rest is copied assets. Each time I run the build process, I remove the dist folder, and create it again. I wonder if there is any way to config webpack, to do the build process only if something is really changed, and if yes, to build the dist incrementally. (Im not talking about the watch option, which is for dev time).

Thanks

user3712353
  • 3,931
  • 4
  • 19
  • 33

1 Answers1

0

I would not do incremental production builds. As you point out, using watch for dev time is fine, but you likely have very different source mapping, minification, etc. settings for your production builds (see webpack guide on development vs. production builds).

But if you are manually removing the /dist folder before every production build, you can at least automate that step with the CleanWebpackPlugin.

From the command line, run:

npm install clean-webpack-plugin --save-dev

Then in your webpack.config.js, add it to the plugins section:

plugins: [
  new CleanWebpackPlugin(["dist"])
],
Joe Wilson
  • 5,591
  • 2
  • 27
  • 38
  • 3
    Joe Wilson, The situation is very common for a any build tool: running "build" multiple times does nothing if no sources, no "dist" were changed. Why rebuild a project if nothing was changed? Why Webpack cannot do it? – Michael Vashchinsky Feb 15 '18 at 10:33
  • You could do that (only one webpack build), but that means you have the same minification, paths, root URLs, source mapping, and more for your local dev and deployed production build? That's not at all common. – Joe Wilson Feb 15 '18 at 17:36
  • 1
    I am talking about prod build only. Building for production 2 times in a row will rebuild the whole project the 2nd time, even though nothing was changed. – Michael Vashchinsky Feb 15 '18 at 20:21