diff --git a/template/build/webpack.prod.conf.js b/template/build/webpack.prod.conf.js index 7ab7bfd..cce3cea 100644 --- a/template/build/webpack.prod.conf.js +++ b/template/build/webpack.prod.conf.js @@ -8,6 +8,7 @@ var ExtractTextPlugin = require('extract-text-webpack-plugin'), HtmlWebpackPlugin = require('html-webpack-plugin'), OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') + SWPrecachePlugin = require('sw-precache-webpack-plugin') module.exports = merge(baseWebpackConfig, { module: { @@ -70,6 +71,29 @@ module.exports = merge(baseWebpackConfig, { new webpack.optimize.CommonsChunkPlugin({ name: 'manifest', chunks: ['vendor'] + }), + // auto generate service-worker for caching static files + new SWPrecachePlugin({ + cacheId: 'quasar-app', + filename: 'service-worker-cache.js', + minify: true, + + staticFileGlobs: [ + 'js/**.js', + 'fonts/**.woff', + 'statics/*', + '/**.html', + '/**.css' + ], + + runtimeCaching: [{ + urlPattern: /\/.*/, + handler: 'cacheFirst' + }], + + dontCacheBustUrlsMatching: /./, + navigateFallback: '/' + }) ] }) diff --git a/template/package.json b/template/package.json index 54ae76c..7ebdcb8 100644 --- a/template/package.json +++ b/template/package.json @@ -16,6 +16,7 @@ "moment": "^2.15.0", "quasar-framework": "^0.13.4", "roboto-fontface": "^0.7.0", + "sw-precache-webpack-plugin": "^0.11.0", "vue": "^2.3.0", "vue-router": "^2.0.0" }, diff --git a/template/src/index.html b/template/src/index.html index d79d5dd..772df97 100644 --- a/template/src/index.html +++ b/template/src/index.html @@ -5,9 +5,15 @@ - +