babel-presets-env 结合一个 target 选项很好的控制了 编译的范围。但是有时候,不想制定这个一个不太准确的 targrt, 而希望更精致的配置,参考文档,就得使用 exclude 了
比如,不希望编译 箭头函数,就在 exclude 里加上 “transform-es2015-arrow-functions”,
{
"presets": [
[
"env",
{
"modules": false,
"useBuiltIns": false,
"exclude": [
"transform-es2015-arrow-functions",
"transform-async-generator-functions"
]
}
]
]
}
但是如果不想编译 async 语法呢?
用这个吗 “transform-async-generator-functions”
报错了:
Invariant Violation: Invalid Option: The plugins/built-ins ‘transform-async-generator-functions’ passed to the ‘exclude’ option are not
valid. Please check data/[plugin-features|built-in-features].js in babel-preset-env (While processing preset: "D:\\learn\\es6\\node_modules\\babel-preset-env\\lib\\index.js")
顺着报错行找下去,法相选项只要不在 validIncludesAndExcludes 的,统统报错:
var validIncludesAndExcludes = [].concat(Object.keys(_plugins2.default), // "../data/plugins.json"
// "./module-transformations"
Object.keys(_moduleTransformations2.default).map(function(m) {return _moduleTransformations2.default[m];
}),
Object.keys(_builtIns2.default), // ../data/built-ins.json
_defaultIncludes.defaultWebIncludes // "./default-includes"
);