4.0.4 • Published 2 months ago

thread-loader v4.0.4

Weekly downloads
1,369,875
License
MIT
Repository
github
Last release
2 months ago

npm node tests coverage discussion size

thread-loader

Runs the following loaders in a worker pool.

Getting Started

npm install --save-dev thread-loader

or

yarn add -D thread-loader

or

pnpm add -D 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!

Examples

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        include: path.resolve('src'),
        use: [
          'thread-loader',
          // your expensive loader (e.g babel-loader)
        ],
      },
    ],
  },
};

with options

use: [
  {
    loader: 'thread-loader',
    // loaders with equal options will share worker pools
    options: {
      // the number of spawned workers, defaults to (number of cpus - 1) or
      // fallback to 1 when require('os').cpus() is undefined
      workers: 2,

      // number of jobs a worker processes in parallel
      // defaults to 20
      workerParallelJobs: 50,

      // additional node.js arguments
      workerNodeArgs: ['--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 development
      poolRespawn: false,

      // timeout for killing the worker processes when idle
      // defaults to 500 (ms)
      // can be set to Infinity for watching builds to keep workers alive
      poolTimeout: 2000,

      // number of jobs the poll distributes to the workers
      // defaults to 200
      // decrease of less efficient but more fair distribution
      poolParallelJobs: 50,

      // name of the pool
      // can be used to create different pools with elsewise identical options
      name: 'my-pool',
    },
  },
  // your expensive loader (e.g babel-loader)
];

prewarming

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 = require('thread-loader');

threadLoader.warmup(
  {
    // pool options, like passed to loader options
    // must match loader options to boot the correct pool
  },
  [
    // modules to load
    // can be any module, i. e.
    'babel-loader',
    'babel-preset-es2015',
    'sass-loader',
  ],
);

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING

License

MIT

zhouhaifei-react-scripts@ishopee/cli-servicevuedragdropuploadimagesplafform-scripts@poloris/sli-vuejautohandywebpack@straw-hat/neutrinomio-cli-servicewandering-cli-serviceaerolito-nextmylicense@rock-kit/ui-webpack-configbuilder-webpack4-vuedowebtempfix-for-version-one-point-one-point-three@rafibarash/react-scripts@nhatle/react-build-tools@zxfan/sky-clipg-cli-service@guomio/cli-servicepanda-scaffoldzjlab-cliecarx-buildnuxt-compactnuxt2bb-chat@nghiepuit/sdk-builderbase-sdk-buildernghiepuit-build-tools@nghiepuit/react-build-toolwebpack-box@yang.bele/webpack5-cli-service@startdt/cli-service@startdt/cli-plugin-babel@startdt/cli-plugin-typescript@joseirrazabal/kit@temporg/ui-webpack-configetsay-webpack-lib@startdt/plugin-babel@startdt/plugin-typescript@startdt/next-servicecousin-serviceelectron-react-tools@electron.land/electron-scripts@ez-fe/ez@zelz/crankdependencies-install-test@gentean/vue-cli-servicenoctis@nehrdani/kickstart@infinitebrahmanuniverse/nolb-threa@inventorjs/plugin-app-react-webpack@renzp/scriptswebpack-kit@everything-registry/sub-chunk-2939vue-cli-service-wc-native-slotsqs-react-scripts@merlion/ape-webpack-configdonate3-sdk-ellencli-plugin-babel-lsq@zhouhaifei/react-scriptstalk-scriptssyue-clitag-loginwkdpackwm-cli-testwm-cli-webpack5web-webpack-configvusion-cli-corevwi-react-scriptsvuniversalvue-cli-plugin-coffeevue-button-test1vue-cli-plugin-babel-testvue-cli-service-chalkfixvue-cli-service-sassjsvue-login-luvue-login-lu1weback_studywebpack_build_customwork-flow-testx-react-jsx-react-scripts-for-pax-react-tsx-vue-jsxj-plugin-babelxj-serviceww-utils-webxhs-mp-compiler-new-clis-helesrmark-react-scriptsrn-razzleshakacode-react-scriptssf-loginsan-cli-plugin-babelsass-and-stuff-react-scriptsscript-webpack-pluginrestartallkill-react-scriptsriant-scriptsteapackage-tatespoorman297
4.0.4

2 months ago

4.0.3

2 months ago

4.0.2

1 year ago

4.0.1

2 years ago

4.0.0

2 years ago

3.0.4

3 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.1.3

5 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.2.0

6 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

8 years ago