rollup.config.mjs中的babel配置如下:
babel({
extensions: ['.js', '.jsx', '.mjs'],
presets: ['@babel/preset-env'],
babelHelpers: 'runtime',
include: ['src/**/*', 'node_modules/@xyflow/**/*'],
}),
babel.config.json的配置如下:
{
"presets": [
[
"@babel/preset-env",
{
"modules": false,
"useBuiltIns": "usage",
"corejs": "3",
"targets": {
"ie": 11
}
}
],
"@babel/preset-react"
],
"plugins": [
[
"@babel/plugin-transform-runtime",
{
"corejs": 3,
"helpers": true,
"regenerator": true,
"babelHelpers": "runtime"
}
],
["@babel/plugin-proposal-class-properties"],
["@babel/plugin-proposal-nullish-coalescing-operator"]
]
}
我希望达到的效果是将@xyflow包中的“??”语法转换,按照上面的配置打包后,文件中依旧包含“??”语法,希望各位大佬解惑
"rollup": "4.22.5",
"@babel/core": "7.25.2",
"@babel/plugin-proposal-class-properties": "7.18.6",
"@babel/plugin-proposal-nullish-coalescing-operator": "7.18.6",
"@babel/plugin-transform-react-jsx": "7.25.2",
"@babel/plugin-transform-runtime": "7.25.4",
"@babel/preset-env": "7.25.4",
"@babel/preset-react": "7.24.7",
"@babel/runtime-corejs3": "7.25.6",
自问自答吧,在babel的plugin中加了个函数,打印了下输出的文件路径,最终定位问题是匹配的规则不对,调整include为
了,路径截图如下: