11const webpack = require ( 'webpack' ) ;
22const path = require ( 'path' ) ;
33const HtmlWebpackPlugin = require ( 'html-webpack-plugin' ) ;
4- const SWPrecacheWebpackPlugin = require ( 'sw-precache-webpack -plugin' ) ;
4+ const OfflinePlugin = require ( 'offline -plugin' ) ;
55
66const nodeEnv = process . env . NODE_ENV || 'development' ;
77const isProd = nodeEnv === 'production' ;
@@ -19,7 +19,6 @@ const plugins = [
1919 new webpack . optimize . CommonsChunkPlugin ( {
2020 name : 'vendor' ,
2121 minChunks : Infinity ,
22- filename : 'vendor.bundle.js'
2322 } ) ,
2423
2524 /**
@@ -39,23 +38,39 @@ const plugins = [
3938 } ) ,
4039
4140 /**
42- * Precache resources using Service Workers
41+ * Precache resources using Service Workers, fallback to appcache
4342 */
44- new SWPrecacheWebpackPlugin ( {
45- cacheId : 'react-dynamic-route-loading-es6' ,
46- filename : 'my-service-worker.js' ,
47- runtimeCaching : [ {
48- handler : 'cacheFirst' ,
49- urlPattern : / ( .* ?) /
50- } ] ,
43+ new OfflinePlugin ( {
44+ relativePaths : false ,
45+ publicPath : '/' ,
46+ updateStrategy : 'all' ,
47+ version : '[hash]' ,
48+ preferOnline : true ,
49+ safeToUseOptionalCaches : true ,
50+ caches : {
51+ main : [ 'core.*.js' ] ,
52+ additional : [ 'chunk.*.js' ] ,
53+ optional : [ ':rest:' ] ,
54+ } ,
55+ excludes : [
56+ '*_webpack_*' ,
57+ ] ,
58+ ServiceWorker : {
59+ navigateFallbackURL : '/' ,
60+ events : true ,
61+ } ,
62+ AppCache : {
63+ FALLBACK : { '/' : '/' } ,
64+ caches : [ 'main' , 'additional' ]
65+ } ,
5166 } ) ,
5267
5368 /**
5469 * Create a JSON file that contains file names of all chunks
5570 */
5671 function ( ) {
5772 const compiler = this ;
58- const chunkRegEx = / ^ c h u n k [ . ] / ;
73+ const chunkRegEx = / ^ c h u n k [ . ] . * j s $ / ;
5974 compiler . plugin ( 'compilation' , function ( compilation ) {
6075 compilation . plugin ( 'html-webpack-plugin-before-html-processing' , function ( htmlPluginData , cb ) {
6176 // find all chunk file names
@@ -113,10 +128,10 @@ if (isProd) {
113128}
114129
115130module . exports = {
116- devtool : isProd ? 'source-map' : 'eval ' ,
131+ devtool : isProd ? 'source-map' : 'cheap-module-source-map ' ,
117132 context : sourcePath ,
118133 entry : {
119- js : [
134+ core : [
120135 'index' ,
121136 'pages/Home'
122137 ] ,
@@ -127,8 +142,8 @@ module.exports = {
127142 } ,
128143 output : {
129144 path : staticsPath ,
130- filename : 'bundle .js' ,
131- chunkFilename : 'chunk.[chunkhash].js' ,
145+ filename : '[name].[chunkhash:8] .js' ,
146+ chunkFilename : 'chunk.[chunkhash:8 ].js' ,
132147 publicPath : '/' ,
133148 } ,
134149 module : {
0 commit comments