From 35d1f44e6662c9c5c7698b63205e7772b135bd2b Mon Sep 17 00:00:00 2001 From: Zakary Date: Thu, 15 Sep 2022 16:12:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(prebundle):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=B0=8F=E7=A8=8B=E5=BA=8F=E4=B8=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=AF=AD=E6=B3=95=E9=97=AE=E9=A2=98=20fix=20#12414?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-jd/src/index.ts | 24 ++++++++++++++++++++++++ packages/taro-swan/src/index.ts | 25 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+) 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 ||= [] + } + }) } From 7b8a2da549ec6ee608cb7cdbeb9ec708e9a9844e Mon Sep 17 00:00:00 2001 From: Zakary Date: Thu, 15 Sep 2022 16:32:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(prebundle):=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=20define=20=E5=8F=82=E6=95=B0=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E4=B8=8D=E5=BF=85=E8=A6=81=E7=9A=84=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=20fix=20#12385?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-webpack5-prebundle/src/prebundle/index.ts | 1 + .../taro-webpack5-prebundle/src/prebundle/scanImports.ts | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/packages/taro-webpack5-prebundle/src/prebundle/index.ts b/packages/taro-webpack5-prebundle/src/prebundle/index.ts index c3346f777b04..8fc879335e0e 100644 --- a/packages/taro-webpack5-prebundle/src/prebundle/index.ts +++ b/packages/taro-webpack5-prebundle/src/prebundle/index.ts @@ -137,6 +137,7 @@ export default class BasePrebundle