Skip to content

Commit

Permalink
feat: options.dev
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya parsa committed Feb 7, 2019
1 parent 58c972f commit fb0d38c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions docs/modules/workbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ workbox: {

(Object) Options to be passed to workbox before using it's modules. By default `debug` field will be set to `false` for production builds.

### `dev`

(Boolean) Enable workbox in dev mode of nuxt. (Disabled by default)

### `importScripts`

(Array) Additional scripts to be imported in service worker script. (Relative to `/`. Can be placed in `assets/` directory)
Expand Down
2 changes: 2 additions & 0 deletions packages/workbox/lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module.exports = {

config: {},

dev: false,

importScripts: [],

offline: true,
Expand Down
5 changes: 3 additions & 2 deletions packages/workbox/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ function getOptions (moduleOptions) {

// swTemplate
if (!options.swTemplate) {
options.swTemplate = path.resolve(__dirname, `../templates/sw${this.options.dev ? '.dev' : ''}.js`)
const disabled = this.options.dev && !options.dev
options.swTemplate = path.resolve(__dirname, `../templates/sw${disabled ? '.disable' : ''}.js`)
}

// swDest
Expand Down Expand Up @@ -70,7 +71,7 @@ function getOptions (moduleOptions) {
// Workbox Config
if (!options.config.debug) {
// Debug field is by default set to true for localhost domain which is not always ideal
options.config.debug = this.options.dev
options.config.debug = options.dev || this.options.dev
}

return options
Expand Down
5 changes: 0 additions & 5 deletions packages/workbox/templates/sw.dev.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/workbox/templates/sw.disable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// THIS FILE SHOULD NOT BE VERSION CONTROLLED
1 change: 1 addition & 0 deletions test/fixture/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {

workbox: {
offlineAnalytics: true,
dev: true,
config: {
debug: true
},
Expand Down

0 comments on commit fb0d38c

Please sign in to comment.