Skip to content

Commit

Permalink
support worker loader
Browse files Browse the repository at this point in the history
  • Loading branch information
jzhng committed Mar 14, 2019
1 parent 2dee2ad commit 9691c46
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
61 changes: 61 additions & 0 deletions packages/react-scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ module.exports = function(webpackEnv) {
// We inferred the "public path" (such as / or /my-project) from homepage.
// We use "/" in development.
publicPath: publicPath,
globalObject: 'this',
// Point sourcemap entries to original disk location (format as URL on Windows)
devtoolModuleFilenameTemplate: isEnvProduction
? info =>
Expand Down Expand Up @@ -250,6 +251,9 @@ module.exports = function(webpackEnv) {
// Keep the runtime chunk separated to enable long term caching
// https://twitter.com/wSokra/status/969679223278505985
runtimeChunk: true,
// Should set back to true when this issue fixed
// https://github.com/webpack-contrib/worker-loader/issues/176
noEmitOnErrors: false,
},
resolve: {
// This allows you to set a fallback for where Webpack should look for modules.
Expand Down Expand Up @@ -338,6 +342,63 @@ module.exports = function(webpackEnv) {
name: 'static/media/[name].[hash:8].[ext]',
},
},
// Process WebWorker JS with Babel.
// The preset includes JSX, Flow, TypeScript, and some ESnext features.
{
test: /\.worker\.(js|mjs|ts)$/,
include: paths.appSrc,
use: [
require.resolve('worker-loader'),
{
loader: require.resolve('babel-loader'),
options: {
customize: require.resolve(
'babel-preset-react-app/webpack-overrides'
),
// @remove-on-eject-begin
babelrc: false,
configFile: false,
presets: [require.resolve('babel-preset-react-app')],
// Make sure we have a unique cache identifier, erring on the
// side of caution.
// We remove this when the user ejects because the default
// is sane and uses Babel options. Instead of options, we use
// the react-scripts and babel-preset-react-app versions.
cacheIdentifier: getCacheIdentifier(
isEnvProduction
? 'production'
: isEnvDevelopment && 'development',
[
'babel-plugin-named-asset-import',
'babel-preset-react-app',
'react-dev-utils',
'react-scripts',
]
),
// @remove-on-eject-end
plugins: [
[
require.resolve('babel-plugin-named-asset-import'),
{
loaderMap: {
svg: {
ReactComponent:
'@svgr/webpack?-prettier,-svgo![path]',
},
},
},
],
],
// 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,
cacheCompression: isEnvProduction,
compact: isEnvProduction,
},
},
],
},
// Process application JS with Babel.
// The preset includes JSX, Flow, TypeScript, and some ESnext features.
{
Expand Down
5 changes: 3 additions & 2 deletions packages/react-scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kaios-scripts",
"version": "0.0.8",
"version": "0.0.9",
"description": "Configuration and scripts for Create KaiOS App.",
"repository": "kaios-design/create-kaios-app",
"license": "MIT",
Expand Down Expand Up @@ -74,7 +74,8 @@
"webpack": "4.28.3",
"webpack-dev-server": "3.1.14",
"webpack-manifest-plugin": "2.0.4",
"workbox-webpack-plugin": "3.6.3"
"workbox-webpack-plugin": "3.6.3",
"worker-loader": "^2.0.0"
},
"devDependencies": {
"react": "^16.3.2",
Expand Down

0 comments on commit 9691c46

Please sign in to comment.