npm install --save-dev thread-loader
Put this loader in front of other loaders. The following loaders run in a worker pool.
Loaders running in a worker pool are limited. Examples:
- Loaders cannot emit files.
- Loaders cannot use custom loader API (i. e. by plugins).
- Loaders cannot access the webpack options.
Each worker is a separate node.js process, which has an overhead of ~600ms. There is also an overhead of inter-process communication.
Use this loader only for expensive operations!
moduleexports =module:rules:test: /\.js$/include: pathuse:"thread-loader"// your expensive loader (e.g babel-loader)
use:loader: "thread-loader"// loaders with equal options will share worker poolsoptions:// the number of spawned workers, defaults to (number of cpus - 1) or// fallback to 1 when require('os').cpus() is undefinedworkers: 2// number of jobs a worker processes in parallel// defaults to 20workerParallelJobs: 50// additional node.js argumentsworkerNodeArgs: '--max-old-space-size=1024'// Allow to respawn a dead worker pool// respawning slows down the entire compilation// and should be set to false for developmentpoolRespawn: false// timeout for killing the worker processes when idle// defaults to 500 (ms)// can be set to Infinity for watching builds to keep workers alivepoolTimeout: 2000// number of jobs the poll distributes to the workers// defaults to 200// decrease of less efficient but more fair distributionpoolParallelJobs: 50// name of the pool// can be used to create different pools with elsewise identical optionsname: "my-pool"// your expensive loader (e.g babel-loader)
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.
const threadLoader = ;threadLoader;