build: also uglify service worker

pull/739/head
Equim 2018-02-25 01:29:45 +08:00
parent 2ca22656d6
commit fe829aa850
No known key found for this signature in database
GPG Key ID: 0534B6F897D268E7
2 changed files with 12 additions and 4 deletions

View File

@ -4,7 +4,7 @@
// Check to make sure service workers are supported in the current browser, // Check to make sure service workers are supported in the current browser,
// and that the current page is accessed from a secure origin. Using a // and that the current page is accessed from a secure origin. Using a
// service worker from an insecure origin will trigger JS console errors. // service worker from an insecure origin will trigger JS console errors.
const isLocalhost = Boolean(window.location.hostname === 'localhost' || var isLocalhost = Boolean(window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address. // [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' || window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4. // 127.0.0.1/8 is considered localhost for IPv4.
@ -26,7 +26,7 @@
// i.e. whether there's an existing service worker. // i.e. whether there's an existing service worker.
if (navigator.serviceWorker.controller) { if (navigator.serviceWorker.controller) {
// The updatefound event implies that registration.installing is set // The updatefound event implies that registration.installing is set
const installingWorker = registration.installing; var installingWorker = registration.installing;
installingWorker.onstatechange = function() { installingWorker.onstatechange = function() {
switch (installingWorker.state) { switch (installingWorker.state) {

View File

@ -84,8 +84,16 @@ var webpackConfig = merge(baseWebpackConfig, {
}, },
// necessary to consistently work with multiple chunks via CommonsChunkPlugin // necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency', chunksSortMode: 'dependency',
serviceWorkerLoader: `<script>${fs.readFileSync(path.join(__dirname, serviceWorkerLoader: (() => {
'./service-worker-prod.js'), 'utf-8')}</script>` let sw = fs.readFileSync(path.join(__dirname, './service-worker-prod.js'), 'utf-8')
let result = UglifyJS.minify(sw)
if (result.error == null) {
sw = result.code
}
return '<script>' + sw + '</script>'
})()
}), }),
// split vendor js into its own file // split vendor js into its own file
new webpack.optimize.CommonsChunkPlugin({ new webpack.optimize.CommonsChunkPlugin({