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-platform-jd/src/program.ts b/packages/taro-platform-jd/src/program.ts index 1a1cefeda218..2b2c42b2c23a 100644 --- a/packages/taro-platform-jd/src/program.ts +++ b/packages/taro-platform-jd/src/program.ts @@ -43,4 +43,14 @@ export default class JD extends TaroPlatformBase { modifyTemplate () { this.template.mergeComponents(this.ctx, components) } + + /** + * 获取jd平台特殊的需要注入env的配置 + * @returns + */ + getTargetPlatformOptions() { + return { + JD_RENDER_TYPE: JSON.stringify(process.env.JD_RENDER_TYPE || ''), + } + } } 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..60dbcd5eb5b5 100644 --- a/packages/taro-service/src/platform-plugin-base/mini.ts +++ b/packages/taro-service/src/platform-plugin-base/mini.ts @@ -113,19 +113,27 @@ ${exampleCommand}`)) return runner.bind(null, appPath) } + // 获取该平台特殊的需要注入env的配置,对应平台需覆盖本方法 + protected getTargetPlatformOptions() { + return {} + } + /** * 准备 runner 参数 * @param extraOptions 需要额外合入 Options 的配置项 */ protected getOptions (extraOptions = {}) { const { ctx, globalObject, fileType, template } = this + // 平台特性注入 + const platformOptions = this.getTargetPlatformOptions() 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()), + ...platformOptions } })