mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
refactor(sw) add directory
This commit is contained in:
parent
ff9834cf24
commit
90c96791be
4 changed files with 20 additions and 17 deletions
|
|
@ -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'),
|
||||
}),
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -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
17
client/sw/register.js
Normal 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();
|
||||
};
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue