diff --git a/packages/shims-node.d.ts b/packages/shims-node.d.ts index 086f7127a45f3dddc582838d6436e89df9be9435..b9d4a0d0ed0b106018e3e295b9fbd7de9f054dad 100644 --- a/packages/shims-node.d.ts +++ b/packages/shims-node.d.ts @@ -12,7 +12,6 @@ declare namespace NodeJS { UNI_CLI_CONTEXT: string UNI_SUBPACKAGE?: string UNI_MP_PLUGIN?: 'true' - UNI_MP_UNIAD?: Boolean UNI_COMPILER_VERSION: string UNI_COMPILER_VERSION_TYPE: 'a' | 'r' UNI_HBUILDERX_PLUGINS: string diff --git a/packages/uni-mp-weixin/src/compiler/options.ts b/packages/uni-mp-weixin/src/compiler/options.ts index 781a92fb3454eef46700dc836cf74877ece82944..ebbe2dbe866047a0244748d9e9923643cc6e726e 100644 --- a/packages/uni-mp-weixin/src/compiler/options.ts +++ b/packages/uni-mp-weixin/src/compiler/options.ts @@ -10,8 +10,6 @@ import { import { UniMiniProgramPluginOptions } from '@dcloudio/uni-mp-vite' import { transformAd } from './transforms/transformAd' -import uniadAppJson from './uniad.app.json' - import source from './project.config.json' export const customElements = [ @@ -100,12 +98,6 @@ export const options: UniMiniProgramPluginOptions = { darkmode: true, subpackages: true, plugins: true, - normalize(appJson) { - if (process.env.UNI_MP_UNIAD == true) { - uniadAppJson(appJson) - } - return appJson - }, }, project: { filename: projectConfigFilename, diff --git a/packages/uni-mp-weixin/src/compiler/transforms/transformAd.ts b/packages/uni-mp-weixin/src/compiler/transforms/transformAd.ts index bd6e1aaf30c581626eea98d3fb778775427b9eee..a53cd8a620f02f8de5baa6e2462e30d555bfae67 100644 --- a/packages/uni-mp-weixin/src/compiler/transforms/transformAd.ts +++ b/packages/uni-mp-weixin/src/compiler/transforms/transformAd.ts @@ -1,4 +1,4 @@ -import { isElementNode } from '@dcloudio/uni-cli-shared' +import { isElementNode, findJsonFile } from '@dcloudio/uni-cli-shared' import { findProp, RootNode, @@ -14,6 +14,10 @@ const AD_COMPONENTS: Array = [ 'ad-interstitial', ] +import uniadAppJson from '../uniad.app.json' + +let appJsonUniadFlag = false + export function transformAd( node: RootNode | TemplateChildNode, context: TransformContext @@ -21,12 +25,18 @@ export function transformAd( if (!isElementNode(node)) { return } + const adpidProp = findProp(node, 'adpid') if (node.tag === 'ad' && adpidProp) { node.tag = 'uniad' node.tagType = ElementTypes.COMPONENT } + + if (appJsonUniadFlag) { + return + } if (AD_COMPONENTS.indexOf(node.tag) > -1) { - process.env.UNI_MP_UNIAD = true + appJsonUniadFlag = true + uniadAppJson(findJsonFile('app')) } }