-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Workbox service worker #4169
Workbox service worker #4169
Changes from 8 commits
b792806
4059079
db75638
7f17257
b25b6e0
ee3c1ae
9a2024e
1a6f48d
f3223c3
9a87859
3dcec0e
88f603a
285e663
7f6e7ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | ||
const ManifestPlugin = require('webpack-manifest-plugin'); | ||
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); | ||
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin'); | ||
const WorkboxWebpackPlugin = require('workbox-webpack-plugin'); | ||
const eslintFormatter = require('react-dev-utils/eslintFormatter'); | ||
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin'); | ||
const paths = require('./paths'); | ||
|
@@ -413,43 +413,21 @@ module.exports = { | |
// having to parse `index.html`. | ||
new ManifestPlugin({ | ||
fileName: 'asset-manifest.json', | ||
publicPath: publicPath | ||
}), | ||
// Generate a service worker script that will precache, and keep up to date, | ||
// the HTML & assets that are part of the Webpack build. | ||
new SWPrecacheWebpackPlugin({ | ||
// By default, a cache-busting query parameter is appended to requests | ||
// used to populate the caches, to ensure the responses are fresh. | ||
// If a URL is already hashed by Webpack, then there is no concern | ||
// about it being stale, and the cache-busting can be skipped. | ||
dontCacheBustUrlsMatching: /\.\w{8}\./, | ||
filename: 'service-worker.js', | ||
logger(message) { | ||
if (message.indexOf('Total precache size is') === 0) { | ||
// This message occurs for every build and is a bit too noisy. | ||
return; | ||
} | ||
if (message.indexOf('Skipping static resource') === 0) { | ||
// This message obscures real errors so we ignore it. | ||
// https://github.com/facebook/create-react-app/issues/2612 | ||
return; | ||
} | ||
console.log(message); | ||
}, | ||
minify: true, | ||
// Don't precache sourcemaps (they're large) and build asset manifest: | ||
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/], | ||
// `navigateFallback` and `navigateFallbackWhitelist` are disabled by default; see | ||
// https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#service-worker-considerations | ||
// navigateFallback: publicUrl + '/index.html', | ||
// navigateFallbackWhitelist: [/^(?!\/__).*/], | ||
publicPath: publicPath, | ||
}), | ||
// Moment.js is an extremely popular library that bundles large locale files | ||
// by default due to how Webpack interprets its code. This is a practical | ||
// solution that requires the user to opt into importing specific locales. | ||
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack | ||
// You can remove this if you don't use Moment.js: | ||
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), | ||
// Generate a service worker script that will precache, and keep up to date, | ||
// the HTML & assets that are part of the Webpack build. | ||
new WorkboxWebpackPlugin.GenerateSW({ | ||
exclude: [/\.map$/, /^(?:asset-)manifest.*\.js(?:on)?$/], | ||
Twaha-Rahman marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On further consideration, I'd go with exclude: [/\.map$/, /asset-manifest\.json$/] here, matching what we were doing with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another option to consider is |
||
navigateFallback: '/index.html', | ||
navigateFallbackWhitelist: [/^(?!\/__).*/], // fix for Firebase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We could also potentially get a little more nuanced, and work around some of the issues raised in #3008 (comment) (which led to And example config could be: {
// ...other options...
navigateFallback: '/index.html',
navigateFallbackBlacklist: [
new RegExp('^/_'),
new RegExp('/[^/]+\.[^/]+$'),
],
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Should the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if there's a trailing slash, we don't want that to be blacklisted. I.e. we do want the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, in the current implementation, the firebase url is a double __ rather than single. Is that correct? If so should the single underscore prefixed urls also be blacklisted? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's safe to go with blacklisting anything that starts with |
||
}), | ||
], | ||
// Some libraries import Node modules but don't use them in the browser. | ||
// Tell Webpack to provide empty mocks for them so importing them works. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,14 +58,14 @@ | |
"react-dev-utils": "^5.0.0", | ||
"style-loader": "0.19.1", | ||
"svgr": "1.8.1", | ||
"sw-precache-webpack-plugin": "0.11.4", | ||
"thread-loader": "1.1.2", | ||
"uglifyjs-webpack-plugin": "1.1.6", | ||
"url-loader": "0.6.2", | ||
"webpack": "3.10.0", | ||
"webpack-dev-server": "2.11.0", | ||
"webpack-manifest-plugin": "1.3.2", | ||
"whatwg-fetch": "2.0.3" | ||
"whatwg-fetch": "2.0.3", | ||
"workbox-webpack-plugin": "^3.0.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're up to |
||
}, | ||
"devDependencies": { | ||
"react": "^16.0.0", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add in
clientsClaim: true
here, which would match the default behavior insw-precache-webpack-plugin
.