Skip to content
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

PRPL: Add Service Worker caching support #15

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions client/index.ejs
Original file line number Diff line number Diff line change
@@ -8,5 +8,10 @@
<body>
<div id="root"></div>
<script>window.__CHUNKS=[];</script>
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/my-service-worker.js');
}
</script>
</body>
</html>
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@
"node-sass": "^3.13.0",
"sass-loader": "^3.2.3",
"style-loader": "^0.13.1",
"sw-precache-webpack-plugin": "^0.7.2",
"webpack": "^2.1.0-beta.27",
"webpack-dev-server": "^2.1.0-beta.10"
},
17 changes: 15 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');

const nodeEnv = process.env.NODE_ENV || 'development';
const isProd = nodeEnv === 'production';
@@ -37,6 +38,18 @@ const plugins = [
template: `${sourcePath}/index.ejs`,
}),

/**
* Precache resources using Service Workers
*/
new SWPrecacheWebpackPlugin({
cacheId: 'react-dynamic-route-loading-es6',
filename: 'my-service-worker.js',
runtimeCaching: [{
handler: 'cacheFirst',
urlPattern: /(.*?)/
}],
}),

/**
* Create a JSON file that contains file names of all chunks
*/
@@ -59,7 +72,7 @@ const plugins = [
cb(null, htmlPluginData);
});
});
},
}
];


@@ -122,7 +135,7 @@ module.exports = {
rules: [
{
test: /\.html$/,
use: 'file-loader',
loader: 'file-loader',
query: {
name: '[name].[ext]'
}