@nuxtjs/workbox
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -6,2 +6,13 @@ # Change Log | ||
<a name="0.3.0"></a> | ||
# [0.3.0](https://github.com/nuxt/modules/compare/@nuxtjs/workbox@0.2.0...@nuxtjs/workbox@0.3.0) (2017-06-04) | ||
### Features | ||
* **workbox:** full offline support ([9ee7f8f](https://github.com/nuxt/modules/commit/9ee7f8f)) | ||
<a name="0.2.0"></a> | ||
@@ -8,0 +19,0 @@ # [0.2.0](https://github.com/nuxt/modules/compare/@nuxtjs/workbox@0.1.0...@nuxtjs/workbox@0.2.0) (2017-06-02) |
34
index.js
const path = require('path') | ||
const workboxPlugin = require('workbox-webpack-plugin'); | ||
const fixUrl = url => url.replace(/(?!^)\/\//g, '/').replace(':/', '://') // // ~> / | ||
const regexEscape = url => url.replace(/\//g, '\\/') // / ~> \/ | ||
const wildcardRegex = url => '/' + regexEscape(fixUrl(url + '/.*')) + '/' // [url] ~> /[escape_url]\/*/ | ||
const isUrl = url => url.indexOf('http') === 0 || url.indexOf('//') === 0 | ||
module.exports = function nuxtWorkbox(options) { | ||
@@ -10,4 +15,6 @@ if (this.options.dev) { | ||
const swFileName = 'sw.js' | ||
const publicPath = this.options.build.publicPath | ||
const routerBase = this.options.router.base | ||
const publicPath = isUrl(this.options.build.publicPath) | ||
? this.options.build.publicPath | ||
: fixUrl(routerBase + this.options.build.publicPath) | ||
@@ -20,11 +27,24 @@ // Add webpack plugin. This plugin internally uses swBuild to generate sw file | ||
swDest: path.resolve(this.options.srcDir, 'static', swFileName), | ||
// navigateFallback: routerBase, // BUG | ||
//navigateFallback: routerBase, // it has some BUGS | ||
directoryIndex: '/', | ||
cacheId: process.env.npm_package_name, | ||
skipWaiting: true, // sw is being registered after onNuxtReady() | ||
clientsClaim: true, | ||
globPatterns: ['**\/*.{js,css}'], | ||
cacheId: process.env.npm_package_name + '_' + process.env.npm_package_version, | ||
skipWaiting: true, // sw is being registered after onNuxtReady() | ||
clientsClaim: true, // the generated service worker will claim any currently open pages | ||
globPatterns: ['**\/*.{js,css,html,json}'], | ||
modifyUrlPrefix: { | ||
'/': publicPath | ||
} | ||
}, | ||
runtimeCaching: [ | ||
// Cache other _nuxt resources runtime | ||
// They are hashed by webpack so are safe to loaded by cacheFirst handler | ||
{ | ||
urlPattern: wildcardRegex(publicPath), | ||
handler: 'cacheFirst' | ||
}, | ||
// Cache routes if offline | ||
{ | ||
urlPattern: wildcardRegex(routerBase), | ||
handler: 'networkFirst' | ||
} | ||
] | ||
}, options))) | ||
@@ -31,0 +51,0 @@ |
{ | ||
"name": "@nuxtjs/workbox", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
9925
218
3