Skip to content

Commit 9691c46

Browse files
committed
support worker loader
from facebook#5886
1 parent 2dee2ad commit 9691c46

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ module.exports = function(webpackEnv) {
168168
// We inferred the "public path" (such as / or /my-project) from homepage.
169169
// We use "/" in development.
170170
publicPath: publicPath,
171+
globalObject: 'this',
171172
// Point sourcemap entries to original disk location (format as URL on Windows)
172173
devtoolModuleFilenameTemplate: isEnvProduction
173174
? info =>
@@ -250,6 +251,9 @@ module.exports = function(webpackEnv) {
250251
// Keep the runtime chunk separated to enable long term caching
251252
// https://twitter.com/wSokra/status/969679223278505985
252253
runtimeChunk: true,
254+
// Should set back to true when this issue fixed
255+
// https://github.com/webpack-contrib/worker-loader/issues/176
256+
noEmitOnErrors: false,
253257
},
254258
resolve: {
255259
// This allows you to set a fallback for where Webpack should look for modules.
@@ -338,6 +342,63 @@ module.exports = function(webpackEnv) {
338342
name: 'static/media/[name].[hash:8].[ext]',
339343
},
340344
},
345+
// Process WebWorker JS with Babel.
346+
// The preset includes JSX, Flow, TypeScript, and some ESnext features.
347+
{
348+
test: /\.worker\.(js|mjs|ts)$/,
349+
include: paths.appSrc,
350+
use: [
351+
require.resolve('worker-loader'),
352+
{
353+
loader: require.resolve('babel-loader'),
354+
options: {
355+
customize: require.resolve(
356+
'babel-preset-react-app/webpack-overrides'
357+
),
358+
// @remove-on-eject-begin
359+
babelrc: false,
360+
configFile: false,
361+
presets: [require.resolve('babel-preset-react-app')],
362+
// Make sure we have a unique cache identifier, erring on the
363+
// side of caution.
364+
// We remove this when the user ejects because the default
365+
// is sane and uses Babel options. Instead of options, we use
366+
// the react-scripts and babel-preset-react-app versions.
367+
cacheIdentifier: getCacheIdentifier(
368+
isEnvProduction
369+
? 'production'
370+
: isEnvDevelopment && 'development',
371+
[
372+
'babel-plugin-named-asset-import',
373+
'babel-preset-react-app',
374+
'react-dev-utils',
375+
'react-scripts',
376+
]
377+
),
378+
// @remove-on-eject-end
379+
plugins: [
380+
[
381+
require.resolve('babel-plugin-named-asset-import'),
382+
{
383+
loaderMap: {
384+
svg: {
385+
ReactComponent:
386+
'@svgr/webpack?-prettier,-svgo![path]',
387+
},
388+
},
389+
},
390+
],
391+
],
392+
// This is a feature of `babel-loader` for webpack (not Babel itself).
393+
// It enables caching results in ./node_modules/.cache/babel-loader/
394+
// directory for faster rebuilds.
395+
cacheDirectory: true,
396+
cacheCompression: isEnvProduction,
397+
compact: isEnvProduction,
398+
},
399+
},
400+
],
401+
},
341402
// Process application JS with Babel.
342403
// The preset includes JSX, Flow, TypeScript, and some ESnext features.
343404
{

packages/react-scripts/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kaios-scripts",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"description": "Configuration and scripts for Create KaiOS App.",
55
"repository": "kaios-design/create-kaios-app",
66
"license": "MIT",
@@ -74,7 +74,8 @@
7474
"webpack": "4.28.3",
7575
"webpack-dev-server": "3.1.14",
7676
"webpack-manifest-plugin": "2.0.4",
77-
"workbox-webpack-plugin": "3.6.3"
77+
"workbox-webpack-plugin": "3.6.3",
78+
"worker-loader": "^2.0.0"
7879
},
7980
"devDependencies": {
8081
"react": "^16.3.2",

0 commit comments

Comments
 (0)