Skip to content

Commit

Permalink
feat: 京东小程序transform渲染模式相关的taro侧改动
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengyanan18 committed Jan 13, 2025
1 parent 786c0bb commit 7da2fb7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/taro-platform-jd/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
})
Expand Down
10 changes: 10 additions & 0 deletions packages/taro-platform-jd/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ''),
}
}
}
4 changes: 4 additions & 0 deletions packages/taro-react/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions packages/taro-runtime/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 9 additions & 1 deletion packages/taro-service/src/platform-plugin-base/mini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})

Expand Down

0 comments on commit 7da2fb7

Please sign in to comment.