[英]ES6 Class extends Array: workaround for ES5 Babel transpile
[英]Unable to transpile es6 to es5 using Babel
我正在使用babel將我的es6代碼轉換為節點應用程序中的es5。
為此,我使用了以下babel節點模塊
“babel-cli”:“6.24.0”
“babel-preset-es2015”:“6.24.0”
“babel-preset-stage-2”:“6.22.0”
以下是package.json中的相關配置
{
"name": "twinconsole",
"version": "1.1.0",
"description": "",
"main": "dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prebuild": "rimraf dist",
"build": "babel --out-dir dist src"
},
"author": "'test@test.com'>",
"license": "MIT",
"devDependencies": {
"babel-cli": "6.24.0",
"babel-preset-es2015": "6.24.0",
"babel-preset-stage-2": "6.22.0",
"rimraf": "2.6.1"
},
"config": {
"babel": {
"presets": ["es2015" , "stage-2"]
}
}
}
我期待下面使用箭頭功能的es6代碼
module.exports.print = msg => {
console.log(msg);
}
被轉化為
module.exports.print = function(msg) {
console.log(msg);
}
相反,轉換后的代碼仍然具有箭頭功能。
知道可能是什么問題。
Babel找不到您的配置,因為您沒有正確設置package.json
。 來自文檔 :
您也可以選擇在package.json中指定.babelrc配置,如下所示:
{ "name": "my-package", "version": "1.0.0", "babel": { // my babel config here } }
請注意, babel
位於頂層,而不是config
內部。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.