Speed up your webpack build/watch speed with webpack-multithread 🚀
The webpack-multithread enables the concurrent execution of multiple webpack configurations, distributing the workload across your processors to notably accelerate the build process.
It uses worker threads to work with multithreading.
Not comperable with node-sass
⚠️
Follow these steps to start using Webpack Multithread:
-
Installation
# with npm npm i webpack-multithread --save-dev # with yarn yarn add webpack-multithread --dev # with pnpm pnpm add webpack-multithread -D
-
Create webpack.multithread.js file
const path = require("path"); const WebpackMultithread = require("webpack-multithread"); const config = path.join(__dirname, "./webpack.config.js"); const webpackMultithread = new WebpackMultithread(config, { cpus: 4, // How many CPUs it may use retries: 2, // Retries before build fail watchMode: true, // Turn on/off watch mode // Options for webpack watcher // https://webpack.js.org/configuration/watch/ watchOptions: { aggregateTimeout: 200, poll: 1000, }, }); webpackMultithread.run();
Your config file should export an array of configs
⚠️ -
Edit package.json
... "scripts": { "start": "NODE_ENV=development node ./config/webpack.multithread.js", "build": "NODE_ENV=production node ./config/webpack.multithread.js" ... } ...