refactor(sw) add directory

This commit is contained in:
coderaiser 2018-05-29 17:47:46 +03:00
parent ff9834cf24
commit 90c96791be
4 changed files with 20 additions and 17 deletions

View file

@ -50,7 +50,7 @@ const rules = clean([
const plugins = [
new EnvironmentPlugin(['NODE_ENV']),
new ServiceWorkerWebpackPlugin({
entry: join(__dirname, '../client', 'sw.js'),
entry: join(__dirname, '..', 'client', 'sw', 'sw.js'),
}),
];

View file

@ -8,12 +8,11 @@ const inherits = require('inherits');
const rendy = require('rendy/legacy');
const exec = require('execon');
const Images = require('./dom/images');
const registerSW = require('./sw/register');
const join = require('join-io/www/join');
const jonny = require('jonny/legacy');
const currify = require('currify/legacy');
const runtime = require('serviceworker-webpack-plugin/lib/runtime');
const bind = (f, ...a) => () => f(...a);
const noop = () => {};
@ -41,7 +40,7 @@ function CloudCmdProto(Util, DOM) {
console.log(str);
};
serviceWorker();
registerSW();
Emitify.call(this);
@ -611,18 +610,5 @@ function CloudCmdProto(Util, DOM) {
});
});
};
function serviceWorker() {
if (!navigator.serviceWorker)
return;
const isHTTPS = location.protocol === 'https:';
const isLocalhost = location.hostname === 'localhost';
if (!isHTTPS && !isLocalhost)
return;
runtime.register();
}
}

17
client/sw/register.js Normal file
View file

@ -0,0 +1,17 @@
'use strict';
const runtime = require('serviceworker-webpack-plugin/lib/runtime');
module.exports = () => {
if (!navigator.serviceWorker)
return;
const isHTTPS = location.protocol === 'https:';
const isLocalhost = location.hostname === 'localhost';
if (!isHTTPS && !isLocalhost)
return;
runtime.register();
};