@nuxtjs/workbox
Advanced tools
Comparing version 0.3.4 to 0.4.0
@@ -6,2 +6,13 @@ # Change Log | ||
<a name="0.4.0"></a> | ||
# [0.4.0](https://github.com/nuxt/modules/compare/@nuxtjs/workbox@0.3.4...@nuxtjs/workbox@0.4.0) (2017-06-06) | ||
### Features | ||
* **workbox:** simplify publicPath & routerBase ([ab1cb77](https://github.com/nuxt/modules/commit/ab1cb77)) | ||
<a name="0.3.4"></a> | ||
@@ -8,0 +19,0 @@ ## [0.3.4](https://github.com/nuxt/modules/compare/@nuxtjs/workbox@0.3.3...@nuxtjs/workbox@0.3.4) (2017-06-05) |
21
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 fixUrl = url => url.replace(/\/\//g, '/').replace(':/', '://') | ||
const wildcardRegex = url => '/' + fixUrl(url + '/.*').replace(/\//g, '\\/') + '/' | ||
const isUrl = url => url.indexOf('http') === 0 || url.indexOf('//') === 0 | ||
@@ -14,7 +13,13 @@ | ||
// routerBase and publicPath | ||
const routerBase = this.options.router.base | ||
let publicPath = fixUrl(`${routerBase}/${this.options.build.publicPath}`) | ||
if (isUrl(this.options.build.publicPath)) { // CDN | ||
publicPath = this.options.build.publicPath | ||
if (publicPath.indexOf('//') === 0) { | ||
publicPath = '/' + publicPath // escape fixUrl | ||
} | ||
} | ||
const swFileName = 'sw.js' | ||
const routerBase = this.options.router.base === '/' ? '' : this.options.router.base | ||
const publicPath = isUrl(this.options.build.publicPath) | ||
? this.options.build.publicPath | ||
: fixUrl(routerBase + this.options.build.publicPath) | ||
@@ -32,3 +37,3 @@ // Add webpack plugin. This plugin internally uses swBuild to generate sw file | ||
modifyUrlPrefix: { | ||
'/': publicPath | ||
'/': fixUrl(publicPath) | ||
}, | ||
@@ -35,0 +40,0 @@ runtimeCaching: [ |
{ | ||
"name": "@nuxtjs/workbox", | ||
"version": "0.3.4", | ||
"version": "0.4.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
5323
5
65