Skip to content

Commit

Permalink
fix(prebundle): 修复部分小程序不支持语法问题 fix #12414
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Sep 20, 2022
1 parent 208d5c4 commit 2e5ce13
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/taro-jd/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { IPluginContext } from '@tarojs/service'
import { isString } from '@tarojs/shared'

import JD from './program'

Expand All @@ -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 ||= []
}
})
}
25 changes: 25 additions & 0 deletions packages/taro-swan/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { IPluginContext } from '@tarojs/service'
import { isString } from '@tarojs/shared'

import Swan from './program'

Expand All @@ -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 ||= []
}
})
}

0 comments on commit 2e5ce13

Please sign in to comment.