Skip to content

Commit 1cdb4cd

Browse files
authored
Merge pull request #2 from goldhand/pwa
Add minify to SWPrecacheWebpackPlugin config / fix readme typos / add more instructions
2 parents 2835105 + a9fb906 commit 1cdb4cd

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ var HtmlWebpackPlugin = require('html-webpack-plugin');
1515
var ExtractTextPlugin = require('extract-text-webpack-plugin');
1616
var ManifestPlugin = require('webpack-manifest-plugin');
1717
var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
18+
var SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
1819
var url = require('url');
1920
var paths = require('./paths');
2021
var getClientEnvironment = require('./env');
21-
var SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
2222

2323
// @remove-on-eject-begin
2424
// `path` is not used after eject - see https://github.com/facebookincubator/create-react-app/issues/1174
@@ -278,6 +278,7 @@ module.exports = {
278278
new SWPrecacheWebpackPlugin({
279279
dontCacheBustUrlsMatching: /\.\w{8}\./,
280280
filename: 'service-worker.js',
281+
minify: true,
281282
navigateFallback: publicUrl + '/index.html',
282283
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/]
283284
})

packages/react-scripts/template/README.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -1084,15 +1084,23 @@ If your production web server does not support HTTPS, then the service worker
10841084
registration will fail, but the rest of your web app will remain functional.
10851085

10861086
1. Service workers are [not currently supported](https://jakearchibald.github.io/isserviceworkerready/)
1087-
in all web browsers. Service worker registration [won't be attempted](src/register-service-worker.js)
1087+
in all web browsers. Service worker registration [won't be attempted](src/service-worker-registration.js)
10881088
on browsers that lack support.
10891089

1090-
1. The service worker is only enabled in the [production environment](#Deployment),
1090+
1. The service worker is only enabled in the [production environment](#deployment),
10911091
e.g. the output of `npm run build`. It's recommended that you do not enable an
10921092
offline-first service worker in a development environment, as it can lead to
10931093
frustration when previously cached assets are used and do not include the latest
10941094
changes you've made locally.
10951095

1096+
1. If you *need* to test your offline-first service worker locally, build
1097+
the application (using `npm run build`) and run a simple http server from your
1098+
build directory. After running the build script, `create-react-app` will give
1099+
instructions for one way to test your production build locally using
1100+
`pushstate-server` and the [deployment instructions](#deployment) have
1101+
instructions for using the python `SimpleHTTPServer`. *Be sure to always use an
1102+
incognito window to avoid complications with your browser cache.*
1103+
10961104
1. If possible,configure your production environment to serve the generated
10971105
`service-worker.js` [with HTTP caching disabled](http://stackoverflow.com/questions/38843970/service-worker-javascript-update-frequency-every-24-hours).
10981106
If that's not possible—[GitHub Pages](#github-pages), for instance, does not
@@ -1111,7 +1119,7 @@ app works offline!" message) and also let them know when the service worker has
11111119
fetched the latest updates that will be available the next time they load the
11121120
page (showing a "New content is available; please refresh." message). Showing
11131121
this messages is currently left as an exercise to the developer, but as a
1114-
starting point, you can make use of the logic included in [`src/register-service-worker.js`](src/register-service-worker.js), which
1122+
starting point, you can make use of the logic included in [`src/service-worker-registration.js`](src/service-worker-registration.js), which
11151123
demonstrates which service worker lifecycle events to listen for to detect each
11161124
scenario, and which as a default, just logs appropriate messages to the
11171125
JavaScript console.
@@ -1122,7 +1130,7 @@ images, or embeds loaded from a different domain. If you would like to use a
11221130
runtime caching strategy for those requests, you can [`eject`](#npm-run-eject)
11231131
and then configure the
11241132
[`runtimeCaching`](https://github.com/GoogleChrome/sw-precache#runtimecaching-arrayobject)
1125-
option in the `SWPrecachePlugin` section of
1133+
option in the `SWPrecacheWebpackPlugin` section of
11261134
[`webpack.config.prod.js`](../config/webpack.config.prod.js).
11271135

11281136
## Deployment

0 commit comments

Comments
 (0)