Skip to content

Commit cc15b84

Browse files
committed
add pwa support
1 parent 1d4461a commit cc15b84

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

template/build/webpack.prod.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const exec = require('child_process').execSync
55
const webpack = require('webpack')
66
const ExtractTextPlugin = require('extract-text-webpack-plugin')
77
const ProgressPlugin = require('webpack/lib/ProgressPlugin')
8+
const OfflinePlugin = require('offline-plugin')
89
const base = require('./webpack.base')
910
const pkg = require('../package')
1011
const _ = require('./utils')
@@ -44,6 +45,15 @@ base.plugins.push(
4445
new webpack.optimize.CommonsChunkPlugin({
4546
name: 'vendor',
4647
filename: 'vendor.[chunkhash:8].js'
48+
}),
49+
// progressive web app
50+
// it uses the publicPath in webpack config
51+
new OfflinePlugin({
52+
relativePaths: false,
53+
AppCache: false,
54+
ServiceWorker: {
55+
events: true
56+
}
4757
})
4858
)
4959

@@ -64,4 +74,16 @@ _.cssProcessors.forEach(processor => {
6474
})
6575
})
6676

77+
// minimize webpack output
78+
base.stats = {
79+
// Add children information
80+
children: false,
81+
// Add chunk information (setting this to `false` allows for a less verbose output)
82+
chunks: false,
83+
// Add built modules information to chunk information
84+
chunkModules: false,
85+
chunkOrigins: false,
86+
modules: false
87+
}
88+
6789
module.exports = base

template/client/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import './promise-polyfill'
22
import {app} from './app'
33

4+
// enable progressive web app support (with offline-plugin)
5+
if (process.env.NODE_ENV === 'production') {
6+
require('./pwa')
7+
}
8+
49
app.$mount('#app')

template/client/pwa.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import runtime from 'offline-plugin/runtime'
2+
3+
runtime.install({
4+
// When an update is ready, tell ServiceWorker to take control immediately:
5+
onUpdateReady() {
6+
console.log('update ready')
7+
runtime.applyUpdate()
8+
},
9+
10+
// Reload to get the new version:
11+
onUpdated() {
12+
console.log('updated')
13+
location.reload()
14+
}
15+
})

template/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"friendly-errors-webpack-plugin": "^1.1.2",
4949
"html-webpack-plugin": "^2.22.0",
5050
"raw-loader": "^0.5.1",
51+
"offline-plugin": "^4.5.3",
5152
"postcss-loader": "^0.9.1",
5253
"postcss-nested": "^1.0.0",
5354
"style-loader": "^0.13.1",

0 commit comments

Comments
 (0)