I'm working on a SBT/Scala web project and I wanted to take advantage of the ES6 features and the new module syntax for the frontend JavaScript layer. SBT has its own build system and I managed to tweak an existing sbt plugin to run webpack to build my JS files using babel. The current solution is a little messy but it works and lives within the sbt build system.
The problem is that it's slow. For every change a new instance of webpack is created and it compiles everything completely from the scratch.
I know I could jump out of the sbt build system and just for the development phase use webpack separately to watch and rebuild my files. But before I do that I was wondering if there are some ways to speed up the webpack build process.
I checked the documentation and it seems to me that any available caching is handled only in memory and that is inapplicable to my case. Or is there some kind of file cache that would survive between separate runs of webpack build? For instance, all of my npm dependencies won't change most of the time so they could be compiled once, cached and then simply included...
You can also speed up babel-loader by as much as 2x by using the cacheDirectory option. This will cache transformations to the filesystem.
Enable caching on the babel-loader babel-loader caches its results in node_modules/. cache/babel-loader by default. After enabling caching with babel-loader we improved the build performance by another 26%. Although configurations vary among locales, most of the modules are the same.
Some configuration to consider:
include
to point at your source. By default it will traverse everything (node_modules
in particular is slow). Make sure you have it setloader: 'babel?cacheDirectory'
.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