From 005c8dd596e672a03743b21cccbaade3b0ee2dc7 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Wed, 1 Dec 2021 12:15:08 +0800 Subject: [PATCH] fix(mp): merge manifest.json into app.json (#3035) --- packages/uni-cli-shared/src/json/mp/index.ts | 2 +- packages/uni-cli-shared/src/json/mp/pages.ts | 15 +++++++++++++++ packages/uni-cli-shared/src/json/mp/project.ts | 4 ++++ packages/uni-mp-vite/src/plugins/pagesJson.ts | 4 ++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/uni-cli-shared/src/json/mp/index.ts b/packages/uni-cli-shared/src/json/mp/index.ts index a73135cb7f..377f19ce33 100644 --- a/packages/uni-cli-shared/src/json/mp/index.ts +++ b/packages/uni-cli-shared/src/json/mp/index.ts @@ -1,4 +1,4 @@ export * from './jsonFile' export { AppJson } from './types' -export { parseMiniProgramPagesJson } from './pages' +export { mergeMiniProgramAppJson, parseMiniProgramPagesJson } from './pages' export { parseMiniProgramProjectJson } from './project' diff --git a/packages/uni-cli-shared/src/json/mp/pages.ts b/packages/uni-cli-shared/src/json/mp/pages.ts index 063f4fc34f..23dac94cef 100644 --- a/packages/uni-cli-shared/src/json/mp/pages.ts +++ b/packages/uni-cli-shared/src/json/mp/pages.ts @@ -6,6 +6,7 @@ import { validatePages } from '../pages' import { AppJson, NetworkTimeout, PageWindowOptions } from './types' import { parseTabBar, parseWindowOptions } from './utils' import { normalizePath } from '../../utils' +import { isMiniProgramProjectJsonKey } from './project' interface ParsePagesJsonOptions { debug?: boolean @@ -25,6 +26,20 @@ export function parseMiniProgramPagesJson( return parsePagesJson(jsonStr, platform, options) } +export function mergeMiniProgramAppJson( + appJson: Record, + platformJson: Record = {} +) { + Object.keys(platformJson).forEach((name) => { + if ( + !isMiniProgramProjectJsonKey(name) && + !['usingComponents', 'optimization'].includes(name) + ) { + appJson[name] = platformJson[name] + } + }) +} + function parsePagesJson( jsonStr: string, platform: UniApp.PLATFORM, diff --git a/packages/uni-cli-shared/src/json/mp/project.ts b/packages/uni-cli-shared/src/json/mp/project.ts index 3f245bd246..ea6affc7fb 100644 --- a/packages/uni-cli-shared/src/json/mp/project.ts +++ b/packages/uni-cli-shared/src/json/mp/project.ts @@ -24,6 +24,10 @@ const projectKeys = [ 'cloudbaseRoot', ] +export function isMiniProgramProjectJsonKey(name: string) { + return projectKeys.includes(name) +} + export function parseMiniProgramProjectJson( jsonStr: string, platform: UniApp.PLATFORM, diff --git a/packages/uni-mp-vite/src/plugins/pagesJson.ts b/packages/uni-mp-vite/src/plugins/pagesJson.ts index 55f16b6d65..4d6903a956 100644 --- a/packages/uni-mp-vite/src/plugins/pagesJson.ts +++ b/packages/uni-mp-vite/src/plugins/pagesJson.ts @@ -12,6 +12,7 @@ import { addMiniProgramPageJson, addMiniProgramAppJson, findChangedJsonFiles, + mergeMiniProgramAppJson, } from '@dcloudio/uni-cli-shared' import { virtualPagePath } from './entry' import { UniMiniProgramPluginOptions } from '../plugin' @@ -61,6 +62,9 @@ export function uniPagesJsonPlugin( resolvedConfig, nvuePages.map((pagePath) => pagePath + options.style.extname) ) + + mergeMiniProgramAppJson(appJson, manifestJson[process.env.UNI_PLATFORM]) + if (options.json?.formatAppJson) { options.json.formatAppJson(appJson, manifestJson, pageJsons) } -- GitLab