Created
December 25, 2017 09:16
-
-
Save kainy/a40cfea1a514ef0e789a1943eb03d0ee to your computer and use it in GitHub Desktop.
使用workbox生成SW脚本的gulpfile配置。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gulp.task('sw', ['copy', 'css', 'js', 'img'], () => { | |
return wbBuild.generateSW({ | |
globDirectory: './www/', | |
swDest: './optimized/sw.js', | |
globPatterns: ["**/*.{css,jpg,png,js,html,shtml}"], | |
ignoreUrlParametersMatching: [/(v|t)/], | |
skipWaiting: true, | |
clientsClaim: true, | |
runtimeCaching: [{ | |
urlPattern : 'https://API-Url/(.*)', | |
handler: 'networkFirst', | |
options: { | |
cacheableResponse: { | |
statuses: [0, 200] | |
} | |
} | |
}, | |
{ | |
urlPattern : 'https://vendor-Url/(.*)', | |
handler: 'cacheFirst', | |
options: { | |
cacheableResponse: { | |
statuses: [0, 200] | |
} | |
} | |
}, | |
{ | |
urlPattern : 'https://CDN-Url/(.*)', | |
handler: 'cacheFirst', | |
options: { | |
cacheableResponse: { | |
statuses: [0, 200] | |
} | |
} | |
}], | |
directoryIndex: 'index.shtml', | |
maximumFileSizeToCacheInBytes: 3000000, | |
globIgnores: ['sw.js'] | |
}) | |
.then(() => { | |
console.log('Service worker generated.'); | |
}) | |
.catch((err) => { | |
console.log('[ERROR] This happened: ' + err); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment