Skip to content

Commit 8289386

Browse files
committed
sw-precache-webpack-plugin, SW registration, manifest.json
1 parent 1228883 commit 8289386

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
1818
var url = require('url');
1919
var paths = require('./paths');
2020
var getClientEnvironment = require('./env');
21+
var SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
2122

2223
// @remove-on-eject-begin
2324
// `path` is not used after eject - see https://github.com/facebookincubator/create-react-app/issues/1174
@@ -273,6 +274,11 @@ module.exports = {
273274
// having to parse `index.html`.
274275
new ManifestPlugin({
275276
fileName: 'asset-manifest.json'
277+
}),
278+
new SWPrecacheWebpackPlugin({
279+
dontCacheBustUrlsMatching: /\.\w{8}\./,
280+
filename: 'service-worker.js',
281+
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/]
276282
})
277283
],
278284
// Some libraries import Node modules but don't use them in the browser.

packages/react-scripts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"recursive-readdir": "2.1.0",
6060
"strip-ansi": "3.0.1",
6161
"style-loader": "0.13.1",
62+
"sw-precache-webpack-plugin": "^0.9.0",
6263
"url-loader": "0.5.7",
6364
"webpack": "2.2.1",
6465
"webpack-dev-server": "2.3.0",

packages/react-scripts/template/public/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<head>
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
67
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
78
<!--
89
Notice the use of %PUBLIC_URL% in the tag above.
@@ -27,5 +28,12 @@
2728
To begin the development, run `npm start`.
2829
To create a production bundle, use `npm run build`.
2930
-->
31+
<script>
32+
if ('%NODE_ENV%' === 'production' && 'serviceWorker' in navigator) {
33+
window.addEventListener('load', function() {
34+
navigator.serviceWorker.register('%PUBLIC_URL%/service-worker.js');
35+
});
36+
}
37+
</script>
3038
</body>
3139
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"short_name": "React App",
3+
"name": "React App",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "192x192",
8+
"type": "image/png"
9+
}
10+
],
11+
"start_url": "./",
12+
"display": "standalone"
13+
}

0 commit comments

Comments
 (0)