Skip to content

Commit b2a21aa

Browse files
jaysonwu991olliecurtisJayson Wu
committed
[LEOP-23]: Add thread-loader to speed up webpack workflow (#93)
* Backpackify * add thread-loader to webpack config * add thread-loader to webpack SSR config but comment that out to not use * add CHANGELOG and upgrade version to v9.1.1 * restore build-brs.yml formation as fork branch Co-authored-by: Ollie Curtis <8831547+olliecurtis@users.noreply.github.com> Co-authored-by: Jayson Wu <jayson.wu@skyscanner.net>
1 parent cb6ab31 commit b2a21aa

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

packages/react-scripts/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## 9.1.0 - UNRELEASED
44

5-
Add `cache-loader` to speed up local development
5+
- Add `thread-loader` to speed up webpack workflow by bundling in parallels
6+
- Add `cache-loader` to speed up local development
67

78
## 9.0.3
89

packages/react-scripts/config/webpack.config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
4040
// @remove-on-eject-end
4141
const postcssNormalize = require('postcss-normalize');
4242

43+
const threadLoader = require('thread-loader');
44+
45+
// This boots the max number of workers in the pool and loads specified modules into the node.js module cache.
46+
const jsWorkerPool = {
47+
// can be set to Infinity for watching builds to keep workers alive
48+
poolTimeout: 2000,
49+
};
50+
51+
// To prevent the high delay when booting workers it possible to warmup the worker pool.
52+
threadLoader.warmup(jsWorkerPool, ['babel-loader']);
53+
4354
const appPackageJson = require(paths.appPackageJson);
4455

4556
const sassFunctions = require('bpk-mixins/sass-functions');
@@ -472,6 +483,10 @@ module.exports = function (webpackEnv) {
472483
...customModuleRegexes,
473484
],
474485
use: [
486+
{
487+
loader: require.resolve('thread-loader'),
488+
options: jsWorkerPool,
489+
},
475490
isEnvDevelopment && {
476491
loader: require.resolve('cache-loader'),
477492
options: {
@@ -545,6 +560,10 @@ module.exports = function (webpackEnv) {
545560
test: /\.(js|mjs)$/,
546561
exclude: /@babel(?:\/|\\{1,2})runtime/,
547562
use: [
563+
{
564+
loader: require.resolve('thread-loader'),
565+
options: jsWorkerPool,
566+
},
548567
isEnvDevelopment && {
549568
loader: require.resolve('cache-loader'),
550569
options: {

packages/react-scripts/config/webpack.config.ssr.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
4040
// @remove-on-eject-end
4141
const postcssNormalize = require('postcss-normalize');
4242

43+
// const threadLoader = require('thread-loader');
44+
45+
// // This boots the max number of workers in the pool and loads specified modules into the node.js module cache.
46+
// const jsWorkerPool = {
47+
// // can be set to Infinity for watching builds to keep workers alive
48+
// poolTimeout: 2000,
49+
// };
50+
51+
// // To prevent the high delay when booting workers it possible to warmup the worker pool.
52+
// threadLoader.warmup(jsWorkerPool, ['babel-loader']);
53+
4354
const appPackageJson = require(paths.appPackageJson);
4455

4556
const sassFunctions = require('bpk-mixins/sass-functions');
@@ -474,6 +485,10 @@ module.exports = function (webpackEnv) {
474485
...customModuleRegexes,
475486
],
476487
use: [
488+
// {
489+
// loader: require.resolve('thread-loader'),
490+
// options: jsWorkerPool,
491+
// },
477492
// isEnvDevelopment && {
478493
// loader: require.resolve('cache-loader'),
479494
// options: {
@@ -547,6 +562,10 @@ module.exports = function (webpackEnv) {
547562
test: /\.(js|mjs)$/,
548563
exclude: /@babel(?:\/|\\{1,2})runtime/,
549564
use: [
565+
// {
566+
// loader: require.resolve('thread-loader'),
567+
// options: jsWorkerPool,
568+
// },
550569
// isEnvDevelopment && {
551570
// loader: require.resolve('cache-loader'),
552571
// options: {

packages/react-scripts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"semver": "7.3.2",
7272
"style-loader": "1.3.0",
7373
"terser-webpack-plugin": "4.2.3",
74+
"thread-loader": "^3.0.3",
7475
"ts-pnp": "1.2.0",
7576
"url-loader": "4.1.1",
7677
"webpack": "4.44.2",

0 commit comments

Comments
 (0)