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 14, 2025
1 parent 786c0bb commit fdcb4d0
Show file tree
Hide file tree
Showing 4 changed files with 23 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
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
12 changes: 11 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,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
}
})

Expand Down

0 comments on commit fdcb4d0

Please sign in to comment.