From d6b6711c324b957bf817a75b1c6a19ffc26c5e21 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Wed, 9 Oct 2019 18:20:25 +0800 Subject: [PATCH] feat: improve compatibility with v3 plugin usage 1. `public/manifest.json` will be used when no `pwa.manifestOptions` present; 2. warn user when there are both the file & the config field present. --- packages/@vue/cli-plugin-pwa/index.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/@vue/cli-plugin-pwa/index.js b/packages/@vue/cli-plugin-pwa/index.js index 462fa81656..f8feae2256 100644 --- a/packages/@vue/cli-plugin-pwa/index.js +++ b/packages/@vue/cli-plugin-pwa/index.js @@ -1,4 +1,20 @@ +const fs = require('fs') +const { chalk, warn } = require('@vue/cli-shared-utils') + module.exports = (api, options) => { + const userOptions = options.pwa || {} + + const manifestPath = api.resolve('public/manifest.json') + if (fs.existsSync(manifestPath)) { + if (!userOptions.manifestOptions) { + userOptions.manifestOptions = require(manifestPath) + } else { + warn( + `The ${chalk.red('public/manifest.json')} file will be ignored in favor of ${chalk.cyan('pwa.manifestOptions')}` + ) + } + } + api.chainWebpack(webpackConfig => { const target = process.env.VUE_CLI_BUILD_TARGET if (target && target !== 'app') { @@ -6,7 +22,6 @@ module.exports = (api, options) => { } const name = api.service.pkg.name - const userOptions = options.pwa || {} // the pwa plugin hooks on to html-webpack-plugin // and injects icons, manifest links & other PWA related tags into