Safari supports service workers now. It's time to add them.
This commit is contained in:
parent
fed32d6f86
commit
f32f0e0ca4
@ -30,11 +30,10 @@
|
|||||||
"semantic-ui-site": "^2.2.12",
|
"semantic-ui-site": "^2.2.12",
|
||||||
"style-loader": "^0.19.0",
|
"style-loader": "^0.19.0",
|
||||||
"styletron": "^2.5.1",
|
"styletron": "^2.5.1",
|
||||||
"styletron-utils": "^2.5.4",
|
"styletron-utils": "^2.5.4"
|
||||||
"webpack": "~3.8.1",
|
|
||||||
"webpack-dev-server": "~2.9.2"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"webpack-dev-server": "~2.4.2"
|
"webpack": "~3.8.1",
|
||||||
|
"webpack-dev-server": "~2.9.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import * as styles from './app.css';
|
|||||||
import { GalleryView } from './interface/gallery.js';
|
import { GalleryView } from './interface/gallery.js';
|
||||||
import { router } from './services/router.js';
|
import { router } from './services/router.js';
|
||||||
import { streamConfig } from './utils/event.js';
|
import { streamConfig } from './utils/event.js';
|
||||||
|
import { log } from './services/console.js';
|
||||||
|
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
|
|
||||||
@ -11,8 +12,19 @@ EventEmitter.defaultMaxListeners = 1000; // https://github.com/pouchdb/pouchdb/i
|
|||||||
|
|
||||||
config({ stream: streamConfig });
|
config({ stream: streamConfig });
|
||||||
|
|
||||||
|
function go() {
|
||||||
// Attach our root view to the DOM
|
// Attach our root view to the DOM
|
||||||
createView(GalleryView, {}).mount(document.body);
|
createView(GalleryView, {}).mount(document.body);
|
||||||
|
|
||||||
// Start the router
|
// Start the router
|
||||||
router.start('home');
|
router.start('home');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('serviceWorker' in navigator) {
|
||||||
|
navigator.serviceWorker
|
||||||
|
.register('/assets/sw.bundle.js', { scope: '/' })
|
||||||
|
.then(go)
|
||||||
|
.catch(go);
|
||||||
|
} else {
|
||||||
|
go();
|
||||||
|
}
|
||||||
|
|||||||
35
packages/gallery/src/sw.js
Normal file
35
packages/gallery/src/sw.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { FileType } from './data/file.js';
|
||||||
|
|
||||||
|
self.addEventListener('fetch', event => {
|
||||||
|
const requestUrl = new URL(event.request.url);
|
||||||
|
|
||||||
|
if (requestUrl.pathname && requestUrl.pathname.startsWith('/file/')) {
|
||||||
|
event.respondWith(
|
||||||
|
FileType.getFromURL(requestUrl.pathname)
|
||||||
|
.then(
|
||||||
|
data =>
|
||||||
|
data
|
||||||
|
? new Response(data, {
|
||||||
|
status: 200,
|
||||||
|
statusText: 'OK',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': data.mimetype
|
||||||
|
}
|
||||||
|
})
|
||||||
|
: new Response(null, {
|
||||||
|
status: 404,
|
||||||
|
statusText: 'NOT FOUND',
|
||||||
|
headers: {}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.catch(
|
||||||
|
() =>
|
||||||
|
new Response(null, {
|
||||||
|
status: 404,
|
||||||
|
statusText: 'NOT FOUND',
|
||||||
|
headers: {}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -5,7 +5,8 @@ const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
context: path.resolve(__dirname, './src'),
|
context: path.resolve(__dirname, './src'),
|
||||||
entry: {
|
entry: {
|
||||||
app: './app.js'
|
app: './app.js',
|
||||||
|
sw: './sw.js'
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
path: path.resolve(__dirname, './dist'),
|
path: path.resolve(__dirname, './dist'),
|
||||||
@ -13,7 +14,10 @@ module.exports = {
|
|||||||
publicPath: '/assets'
|
publicPath: '/assets'
|
||||||
},
|
},
|
||||||
devServer: {
|
devServer: {
|
||||||
contentBase: path.resolve(__dirname, './src')
|
contentBase: path.resolve(__dirname, './src'),
|
||||||
|
headers: {
|
||||||
|
'Service-Worker-Allowed': '/'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
@ -27,6 +31,7 @@ module.exports = {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
|
new webpack.optimize.CommonsChunkPlugin({}),
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
__DEV__: true
|
__DEV__: true
|
||||||
}),
|
}),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user