From 010fe0e0ec0266c39392c831020d477bbb0e3acc Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Sat, 8 Jun 2019 13:59:04 +0430 Subject: [PATCH] feat: `pwa.` scopped options --- docs/modules/icon.md | 8 +++++--- docs/modules/manifest.md | 10 ++++++---- docs/modules/meta.md | 6 +++--- docs/modules/workbox.md | 8 +++++--- lib/module.js | 7 +++++-- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/docs/modules/icon.md b/docs/modules/icon.md index 1beb8317..5a20965e 100644 --- a/docs/modules/icon.md +++ b/docs/modules/icon.md @@ -10,11 +10,13 @@ sidebar: auto This module automatically generates app icons and favicon with different sizes using [jimp](https://github.com/oliver-moran/jimp) and fills `manifest.icons[]` with proper paths to generated assets that is used by manifest module. Source icon is being resized using *cover* method. -You can pass options to `icon` section in `nuxt.config.js` to override defaults. +You can pass options to `pwa.icon` in `nuxt.config.js` to override defaults. ```js -icon: { - // Icon options +pwa: { + icon: { + /* icon options */ + } } ``` diff --git a/docs/modules/manifest.md b/docs/modules/manifest.md index b6871299..70fdd3d6 100644 --- a/docs/modules/manifest.md +++ b/docs/modules/manifest.md @@ -9,11 +9,13 @@ sidebar: auto Manifest adds [Web App Manifest](https://developer.mozilla.org/en-US/docs/Web/Manifest) with no pain. -You can pass options to `manifest` section in `nuxt.config.js` to override defaults. +You can pass options to `pwa.manifest` in `nuxt.config.js` to override defaults. ```js -manifest: { - name: 'My Awesome App', - lang: 'fa' +pwa: { + manifest: { + name: 'My Awesome App', + lang: 'fa' + } } ``` diff --git a/docs/modules/meta.md b/docs/modules/meta.md index 74d8f03f..2c05fa0c 100644 --- a/docs/modules/meta.md +++ b/docs/modules/meta.md @@ -8,12 +8,12 @@ sidebar: auto [![npm (scoped with tag)](https://img.shields.io/npm/v/@nuxtjs/meta/latest.svg?style=flat-square)](https://npmjs.com/package/@nuxtjs/meta) Meta easily adds common meta tags into your project with zero-config needed. -You can optionally override meta using either `manifest` or `meta` section of `nuxt.config.js`: +You can optionally override meta using `pwa.meta` in `nuxt.config.js`: ```js -{ +pwa: { meta: { - // ... + /* meta options */ } } ``` diff --git a/docs/modules/workbox.md b/docs/modules/workbox.md index 24144dbc..cb451bca 100644 --- a/docs/modules/workbox.md +++ b/docs/modules/workbox.md @@ -10,11 +10,13 @@ sidebar: auto Workbox is a collection of JavaScript libraries for Progressive Web Apps. ([Learn more](https://developers.google.com/web/tools/workbox)). This module adds full offline support using workbox. -You can pass options to `workbox` section in `nuxt.config.js` to override the [defaults](https://github.com/nuxt-community/pwa-module/blob/master/packages/workbox/lib/defaults.js). +You can pass options to `pwa.workbox` in `nuxt.config.js` to override the [defaults](https://github.com/nuxt-community/pwa-module/blob/dev/lib/workbox/defaults.js). ```js -workbox: { - // Workbox options +pwa: { + workbox: { + /* workbox options */ + } } ``` diff --git a/lib/module.js b/lib/module.js index e11ba240..e38417ed 100755 --- a/lib/module.js +++ b/lib/module.js @@ -1,11 +1,14 @@ module.exports = async function nuxtPWA (options) { const modules = ['icon', 'manifest', 'meta', 'workbox'] + + const pwaOptions = { ...this.options.pwa, ...options } + for (const name of modules) { - if (options[name] === false || this.options[name] === false) { + if (pwaOptions[name] === false || this.options[name] === false) { continue } const moduleFn = require(`./${name}/module.js`) - const moduleOptions = { ...this.options[name], ...options[name] } + const moduleOptions = { ...this.options[name], ...pwaOptions[name] } await moduleFn.call(this, moduleOptions) } }