Skip to content

Commit 2ec7eaa

Browse files
committed
Add support for WebWorker with worker-loader (facebook#3660)
1 parent 3e16544 commit 2ec7eaa

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

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

+26
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,32 @@ module.exports = {
213213
name: 'static/media/[name].[hash:8].[ext]',
214214
},
215215
},
216+
// Process WebWorkder JS with Babel.
217+
// The preset includes JSX, Flow, and some ESnext features.
218+
{
219+
test: /\.worker\.(js|jsx|mjs)$/,
220+
include: paths.appSrc,
221+
use: [
222+
require.resolve('worker-loader'),
223+
// This loader parallelizes code compilation, it is optional but
224+
// improves compile time on larger projects
225+
require.resolve('thread-loader'),
226+
{
227+
loader: require.resolve('babel-loader'),
228+
options: {
229+
// @remove-on-eject-begin
230+
babelrc: false,
231+
presets: [require.resolve('babel-preset-react-app')],
232+
// @remove-on-eject-end
233+
// This is a feature of `babel-loader` for webpack (not Babel itself).
234+
// It enables caching results in ./node_modules/.cache/babel-loader/
235+
// directory for faster rebuilds.
236+
cacheDirectory: true,
237+
highlightCode: true,
238+
},
239+
},
240+
],
241+
},
216242
// Process application JS with Babel.
217243
// The preset includes JSX, Flow, and some ESnext features.
218244
{

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

+23
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,29 @@ module.exports = {
252252
name: 'static/media/[name].[hash:8].[ext]',
253253
},
254254
},
255+
// Process WebWorkder JS with Babel.
256+
// The preset includes JSX, Flow, and some ESnext features.
257+
{
258+
test: /\.worker\.(js|jsx|mjs)$/,
259+
include: paths.appSrc,
260+
use: [
261+
require.resolve('worker-loader'),
262+
// This loader parallelizes code compilation, it is optional but
263+
// improves compile time on larger projects
264+
require.resolve('thread-loader'),
265+
{
266+
loader: require.resolve('babel-loader'),
267+
options: {
268+
// @remove-on-eject-begin
269+
babelrc: false,
270+
presets: [require.resolve('babel-preset-react-app')],
271+
// @remove-on-eject-end
272+
compact: true,
273+
highlightCode: true,
274+
},
275+
},
276+
],
277+
},
255278
// Process application JS with Babel.
256279
// The preset includes JSX, Flow, and some ESnext features.
257280
{

packages/react-scripts/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
"webpack": "4.8.3",
7171
"webpack-dev-server": "3.1.4",
7272
"webpack-manifest-plugin": "2.0.3",
73-
"whatwg-fetch": "2.0.4"
73+
"whatwg-fetch": "2.0.4",
74+
"worker-loader": "^1.1.1"
7475
},
7576
"devDependencies": {
7677
"react": "^16.3.2",

0 commit comments

Comments
 (0)