我看在HBuilderX\plugins\uniapp-cli下有个babel.config.js,但是里面的内容是这样的,如下
const plugins = []
if (process.env.UNI_OPT_TREESHAKINGNG) {
plugins.push(require('@dcloudio/vue-cli-plugin-uni-optimize/packages/babel-plugin-uni-api/index.js'))
}
if (
(
process.env.UNI_PLATFORM === 'app-plus' &&
process.env.UNI_USING_V8
) ||
(
process.env.UNI_PLATFORM === 'h5' &&
process.env.UNI_H5_BROWSER === 'builtin'
)
) {
const path = require('path')
const isWin = /^win/.test(process.platform)
const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
const input = normalizePath(process.env.UNI_INPUT_DIR)
try {
plugins.push([
require('@dcloudio/vue-cli-plugin-hbuilderx/packages/babel-plugin-console'),
{
file (file) {
file = normalizePath(file)
if (file.indexOf(input) === 0) {
return path.relative(input, file)
}
return false
}
}
])
} catch (e) {}
}
process.UNI_LIBRARIES = process.UNI_LIBRARIES || ['@dcloudio/uni-ui']
process.UNI_LIBRARIES.forEach(libraryName => {
plugins.push([
'import',
{
'libraryName': libraryName,
'customName': (name) => {
return `${libraryName}/lib/${name}/${name}`
}
}
])
})
module.exports = {
retainLines: process.env.NODE_ENV !== 'production',
presets: [
[
'@vue/app',
{
modules: 'commonjs',//可支持 module.exports 与 import 混搭使用
useBuiltIns: process.env.UNI_PLATFORM === 'h5' ? 'usage' : 'entry',
exclude: ['transform-typeof-symbol']
}
]
],
plugins
}
我想用babel编译es2020的语法,想加下面的几行代码,要怎么加进去呢?
module.exports = {
presets:[
'@vue/cli-plugin-babel/preset'
],
plugins:[
"@babel/plugin-proposal-optional-chaining"
]
}
2***@qq.com (作者)
对创建的所有项目生效倒是没关系,这样看的话也就是通过修改安装目录下的babel.config.js能实现自由选择babel插件?大神你知道修改方法吗?
2022-06-15 13:32
DCloud_UNI_WZF
回复 2***@qq.com: 目前 HBuilderX 不支持修改 babel 配置,推荐使用 cli 方式创建项目并修改。
2022-06-15 14:57