From fdcb4d0381660af928ac0265f8a73d5133fa91bc Mon Sep 17 00:00:00 2001 From: zhengyanan18 Date: Tue, 14 Jan 2025 09:02:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BA=AC=E4=B8=9C=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8Ftransform=E6=B8=B2=E6=9F=93=E6=A8=A1=E5=BC=8F=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84taro=E4=BE=A7=E6=94=B9=E5=8A=A8(=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E7=89=88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-platform-jd/src/index.ts | 3 +++ packages/taro-react/src/props.ts | 4 ++++ packages/taro-runtime/src/utils/index.ts | 5 +++++ .../taro-service/src/platform-plugin-base/mini.ts | 12 +++++++++++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/taro-platform-jd/src/index.ts b/packages/taro-platform-jd/src/index.ts index 217be7308d8e..2c55b4f26d9f 100644 --- a/packages/taro-platform-jd/src/index.ts +++ b/packages/taro-platform-jd/src/index.ts @@ -13,6 +13,9 @@ export default (ctx: IPluginContext) => { useConfigName: 'mini', async fn ({ config }) { const program = new JD(ctx, config) + if (config.useTransformRender) { + process.env.JD_RENDER_TYPE = 'transform' + } await program.start() } }) diff --git a/packages/taro-react/src/props.ts b/packages/taro-react/src/props.ts index 4c37046ea7e3..0213a39c0d08 100644 --- a/packages/taro-react/src/props.ts +++ b/packages/taro-react/src/props.ts @@ -131,6 +131,10 @@ function setEvent (dom: TaroElement, name: string, value: unknown, oldValue?: un dom.addEventListener(eventName, value, process.env.TARO_PLATFORM !== PLATFORM_TYPE.HARMONY ? { isCapture, sideEffect: false } : undefined) } else { dom.addEventListener(eventName, value, process.env.TARO_PLATFORM !== PLATFORM_TYPE.HARMONY ? isCapture : undefined) + // 京东小程序transform模式: 把事件绑定写到data里 + if (process.env.JD_RENDER_TYPE === 'transform') { + dom.setAttribute(`bind${eventName}`, 'eh') + } } } else { dom.removeEventListener(eventName, oldValue as any) diff --git a/packages/taro-runtime/src/utils/index.ts b/packages/taro-runtime/src/utils/index.ts index 82122f77d9b7..c3c4a84cb760 100644 --- a/packages/taro-runtime/src/utils/index.ts +++ b/packages/taro-runtime/src/utils/index.ts @@ -123,9 +123,14 @@ export function extend (ctor: Ctor, methodName: string, options: TFunc | Record< } let componentsAlias +declare let jd: any export function getComponentsAlias () { if (!componentsAlias) { componentsAlias = _getComponentsAlias(internalComponents) + // 京东小程序transform模式, 把mapping传入基础库 + if (process.env.JD_RENDER_TYPE === 'transform') { + jd && jd.setMapping && jd.setMapping(componentsAlias) + } } return componentsAlias } diff --git a/packages/taro-service/src/platform-plugin-base/mini.ts b/packages/taro-service/src/platform-plugin-base/mini.ts index 6c6dc750cb60..82f200d43c75 100644 --- a/packages/taro-service/src/platform-plugin-base/mini.ts +++ b/packages/taro-service/src/platform-plugin-base/mini.ts @@ -113,19 +113,29 @@ ${exampleCommand}`)) return runner.bind(null, appPath) } + // 获取平台相关的其他需要注入env全局的变量(例如运行时变量) + private getOtherOptions() { + return { + JD_RENDER_TYPE: JSON.stringify(process.env.JD_RENDER_TYPE || ''), // 京东小程序的渲染类型,运行时变量 + } + } + /** * 准备 runner 参数 * @param extraOptions 需要额外合入 Options 的配置项 */ protected getOptions (extraOptions = {}) { const { ctx, globalObject, fileType, template } = this + // 其他特性注入 + const otherOptions = this.getOtherOptions() const config = recursiveMerge(Object.assign({}, this.config), { env: { FRAMEWORK: JSON.stringify(this.config.framework), TARO_ENV: JSON.stringify(this.platform), TARO_PLATFORM: JSON.stringify(this.platformType), - TARO_VERSION: JSON.stringify(getPkgVersion()) + TARO_VERSION: JSON.stringify(getPkgVersion()), + ...otherOptions } })