Skip to content

Commit c3fc2e5

Browse files
committed
fix(helper): 修复配置文件读取报错的问题,fix #12674
1 parent e529d3c commit c3fc2e5

File tree

8 files changed

+2269
-6
lines changed

8 files changed

+2269
-6
lines changed

packages/taro-helper/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
swc/**/.cargo
2+
swc/**/target/*
3+
!swc/**/target/wasm32-wasi
4+
swc/**/target/wasm32-wasi/*
5+
!swc/**/target/wasm32-wasi/release
6+
swc/**/target/wasm32-wasi/release/*
7+
!swc/**/target/wasm32-wasi/release/*.wasm

packages/taro-helper/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"files": [
2121
"index.js",
2222
"dist",
23-
"types"
23+
"types",
24+
"swc"
2425
],
2526
"keywords": [
2627
"taro"

packages/taro-helper/src/swcRegister.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ export class InjectDefineConfigHeader extends Visitor {
1818

1919
interface ICreateSwcRegisterParam {
2020
only
21-
plugin?
21+
plugins: [string, any][]
2222
}
2323

24-
export default function createSwcRegister ({ only, plugin }: ICreateSwcRegisterParam) {
24+
export default function createSwcRegister ({ only, plugins }: ICreateSwcRegisterParam) {
2525
const config: Record<string, any> = {
2626
only: Array.from(new Set([...only])),
2727
jsc: {
@@ -38,7 +38,11 @@ export default function createSwcRegister ({ only, plugin }: ICreateSwcRegisterP
3838
}
3939
}
4040

41-
if (plugin) config.plugin = plugin
41+
if (plugins) {
42+
config.jsc.experimental = {
43+
plugins
44+
}
45+
}
4246

4347
require('@swc/register')(config)
4448
}

packages/taro-helper/src/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
SCRIPT_EXT,
1616
TARO_CONFIG_FOLDER
1717
} from './constants'
18-
import createSwcRegister, { InjectDefineConfigHeader } from './swcRegister'
18+
import createSwcRegister from './swcRegister'
1919
import { chalk } from './terminal'
2020

2121
const execSync = child_process.execSync
@@ -649,7 +649,9 @@ export function readConfig (configPath: string) {
649649
configPath,
650650
filepath => importPaths.includes(filepath)
651651
],
652-
plugin: m => new InjectDefineConfigHeader().visitProgram(m)
652+
plugins: [
653+
[path.resolve(__dirname, '../swc/plugin-define-config/target/wasm32-wasi/release/swc_plugin_define_config.wasm'), {}]
654+
]
653655
})
654656

655657
importPaths.concat([configPath]).forEach(item => {

0 commit comments

Comments
 (0)