diff --git a/packages/taro-jd/src/index.ts b/packages/taro-jd/src/index.ts index 77698fa7c769..051d956d778c 100644 --- a/packages/taro-jd/src/index.ts +++ b/packages/taro-jd/src/index.ts @@ -1,4 +1,5 @@ import type { IPluginContext } from '@tarojs/service' +import { isString } from '@tarojs/shared' import JD from './program' @@ -14,4 +15,27 @@ export default (ctx: IPluginContext) => { await program.start() } }) + + ctx.modifyRunnerOpts(({ opts }) => { + if (!opts?.compiler) return + + if (isString(opts.compiler)) { + opts.compiler = { + type: opts.compiler + } + } + const { compiler } = opts + if (compiler.type === 'webpack5') { + compiler.prebundle ||= {} + const prebundleOptions = compiler.prebundle + if (prebundleOptions.enable === false) return + prebundleOptions.swc ||= { + jsc: { + target: 'es5' + } + } + prebundleOptions.exclude ||= [] + prebundleOptions.include ||= [] + } + }) } diff --git a/packages/taro-swan/src/index.ts b/packages/taro-swan/src/index.ts index 4b883b5a8450..63c624bdb1bf 100644 --- a/packages/taro-swan/src/index.ts +++ b/packages/taro-swan/src/index.ts @@ -1,4 +1,5 @@ import type { IPluginContext } from '@tarojs/service' +import { isString } from '@tarojs/shared' import Swan from './program' @@ -14,4 +15,28 @@ export default (ctx: IPluginContext) => { await program.start() } }) + + ctx.modifyRunnerOpts(({ opts }) => { + if (!opts?.compiler) return + + if (isString(opts.compiler)) { + opts.compiler = { + type: opts.compiler + } + } + const { compiler } = opts + if (compiler.type === 'webpack5') { + compiler.prebundle ||= {} + const prebundleOptions = compiler.prebundle + if (prebundleOptions.enable === false) return + prebundleOptions.swc ||= { + jsc: { + // Note: 由于百度小程序不支持 ES2015,所以这里需要将 ES5 (模拟器环境可无该问题) + target: 'es5' + } + } + prebundleOptions.exclude ||= [] + prebundleOptions.include ||= [] + } + }) }