Webpack build time in Heroku

If you have a complex build and you have enabled caching but you still don't see any significant improvements, then the culprit might be that you haven't enabled babel caching:

Future webpack builds will attempt to read from the cache to avoid needing to run the potentially expensive Babel recompilation process on each run

If you have enabled it with default options and you delete the node_modules on every build, then you are also deleting the babel caching.

If you already have caching enabled and is not being deleted, then parallelisation of the babel process via threads can give you a extra boost.

Below you will find a partial webpack config with caching and thread workers.

import { warmup } from 'thread-loader';
// ...
// timeout for killing the worker processes when idle
// defaults to 500 (ms)
const threadConfig = { poolTimeout: 2000 };

// To prevent the high delay when booting workers it possible to warmup the worker pool. This boots the max number of workers in the pool and loads specified modules into the node.js module cache.
warmup(threadConfig, ['babel-loader']);

const cfg = {
	mode: 'production',
	entry: {
		app: './src/app.js',
    	vendors: './src/vendors.js'
  	},
  	module: {
  		rules: [{
    		test: /\.js$/,
			use: [
				{
		      		loader: 'thread-loader',
		        	options: threadConfig,
		       },
		       'babel-loader?cacheDirectory=.babel_cache',
		    ],
    		exclude: /node_modules/,
  		}]
  },
  //...
}