Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for WebWorker with worker-loader (#3660) #3934

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/react-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,32 @@ module.exports = {
name: 'static/media/[name].[hash:8].[ext]',
},
},
// Process WebWorkder JS with Babel.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo. WebWorkers

// The preset includes JSX, Flow, and some ESnext features.
{
test: /\.worker\.(js|jsx|mjs)$/,
include: paths.appSrc,
use: [
require.resolve('worker-loader'),
// This loader parallelizes code compilation, it is optional but
// improves compile time on larger projects
require.resolve('thread-loader'),
{
loader: require.resolve('babel-loader'),
options: {
// @remove-on-eject-begin
babelrc: false,
presets: [require.resolve('babel-preset-react-app')],
// @remove-on-eject-end
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
// directory for faster rebuilds.
cacheDirectory: true,
highlightCode: true,
},
},
],
},
// Process application JS with Babel.
// The preset includes JSX, Flow, and some ESnext features.
{
Expand Down
23 changes: 23 additions & 0 deletions packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,29 @@ module.exports = {
name: 'static/media/[name].[hash:8].[ext]',
},
},
// Process WebWorkder JS with Babel.
// The preset includes JSX, Flow, and some ESnext features.
{
test: /\.worker\.(js|jsx|mjs)$/,
include: paths.appSrc,
use: [
require.resolve('worker-loader'),
// This loader parallelizes code compilation, it is optional but
// improves compile time on larger projects
require.resolve('thread-loader'),
{
loader: require.resolve('babel-loader'),
options: {
// @remove-on-eject-begin
babelrc: false,
presets: [require.resolve('babel-preset-react-app')],
// @remove-on-eject-end
compact: true,
highlightCode: true,
},
},
],
},
// Process application JS with Babel.
// The preset includes JSX, Flow, and some ESnext features.
{
Expand Down
3 changes: 2 additions & 1 deletion packages/react-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
"webpack": "4.8.3",
"webpack-dev-server": "3.1.4",
"webpack-manifest-plugin": "2.0.3",
"whatwg-fetch": "2.0.4"
"whatwg-fetch": "2.0.4",
"worker-loader": "^1.1.1"
},
"devDependencies": {
"react": "^16.3.2",
Expand Down