From 4094858c5bb6338a5efcf4d604c8b084936e7f21 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Tue, 7 Jun 2022 13:29:46 +0800 Subject: [PATCH] fix(mp): remove unused key (app.json) --- .../lib/platforms/mp-alipay.js | 25 ++++++++----------- .../lib/platforms/mp.js | 5 ++-- packages/webpack-uni-pages-loader/lib/util.js | 15 ++++++++--- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/packages/webpack-uni-pages-loader/lib/platforms/mp-alipay.js b/packages/webpack-uni-pages-loader/lib/platforms/mp-alipay.js index 24dc3e42b3..c33cb05e1b 100644 --- a/packages/webpack-uni-pages-loader/lib/platforms/mp-alipay.js +++ b/packages/webpack-uni-pages-loader/lib/platforms/mp-alipay.js @@ -9,7 +9,8 @@ const { const { hasOwn, parseStyle, - parseTabBar + parseTabBar, + NON_APP_JSON_KEYS } = require('../util') function defaultCopy (name, value, json) { @@ -38,6 +39,8 @@ function copyToJson (json, fromJson, options) { }) } +const projectKeys = ['component2', 'enableAppxNg'] + module.exports = function (pagesJson, manifestJson) { const app = { pages: [], @@ -72,9 +75,7 @@ module.exports = function (pagesJson, manifestJson) { const platformJson = manifestJson['mp-alipay'] || {} Object.keys(platformJson).forEach(key => { - if ( - ['usingComponents', 'optimization', 'uniStatistics', 'appid'].indexOf(key) === -1 - ) { + if (!projectKeys.includes(key) && !NON_APP_JSON_KEYS.includes(key)) { // usingComponents 是编译模式开关,需要过滤,不能拷贝到 app app[key] = platformJson[key] } @@ -84,16 +85,12 @@ module.exports = function (pagesJson, manifestJson) { updateAppJsonUsingComponents(app.usingComponents) } - const project = Object.assign({}, manifestJson['mp-alipay'] || {}) - delete project.usingComponents - delete project.plugins - delete project.useDynamicPlugins - if (!hasOwn(project, 'component2')) { - project.component2 = true - } - if (!hasOwn(project, 'enableAppxNg')) { - project.enableAppxNg = true - } + const project = Object.assign({ + appid: platformJson.appid + }) + + project.component2 = hasOwn(platformJson, 'component2') ? platformJson.component2 : true + project.enableAppxNg = hasOwn(platformJson, 'enableAppxNg') ? platformJson.enableAppxNg : true return [{ name: 'app', diff --git a/packages/webpack-uni-pages-loader/lib/platforms/mp.js b/packages/webpack-uni-pages-loader/lib/platforms/mp.js index 81f88b3242..b47e4cae0e 100644 --- a/packages/webpack-uni-pages-loader/lib/platforms/mp.js +++ b/packages/webpack-uni-pages-loader/lib/platforms/mp.js @@ -20,7 +20,8 @@ const { const { hasOwn, parseStyle, - trimMPJson + trimMPJson, + NON_APP_JSON_KEYS } = require('../util') const uniI18n = require('@dcloudio/uni-cli-i18n') @@ -262,7 +263,7 @@ module.exports = function (pagesJson, manifestJson, project = {}) { Object.keys(platformJson).forEach(key => { if ( - !projectKeys.includes(key) && ['usingComponents', 'optimization'].indexOf(key) === -1 + !projectKeys.includes(key) && !NON_APP_JSON_KEYS.includes(key) ) { // usingComponents 是编译模式开关,需要过滤,不能拷贝到 app app[key] = platformJson[key] diff --git a/packages/webpack-uni-pages-loader/lib/util.js b/packages/webpack-uni-pages-loader/lib/util.js index 39e8947abd..6b5d22e1b0 100644 --- a/packages/webpack-uni-pages-loader/lib/util.js +++ b/packages/webpack-uni-pages-loader/lib/util.js @@ -129,10 +129,19 @@ function parseTabBar (style = {}) { return style } - +const NON_APP_JSON_KEYS = [ + 'appid', + 'unipush', + 'usingComponents', + 'optimization', + 'scopedSlotsCompiler', + 'usingComponents', + 'uniStatistics' +] module.exports = { hasOwn, parseStyle, parseTabBar, - trimMPJson -} + trimMPJson, + NON_APP_JSON_KEYS +} -- GitLab