【发布时间】:2015-12-01 22:40:41
【问题描述】:
我试图在 babeljs 的try it out 标签中转换下面的代码 -
class aboutController{
constructor(ajaxService){
this.ajaxService = ajaxService;
this.printLog();
}
printLog(){
this.ajaxService.log();
}
static $inject = ["ajaxService"];
}
静态关键字被转换成
{
key: "$inject",
value: ["ajaxService"],
enumerable: true
}
然后我尝试了 grunt-babel 任务来自动化构建。我的 gruntfile.js 看起来像这样 -
module.exports = function(grunt){
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
babel: {
options: {
sourceMap: true,
highlightCode: true
},
es6: {
files: [
{
expand: true,
src: ['components/**/*.es6'],
ext: '.js'
}
]
}
},
watch: {
scripts: {
files: ['components/**/*.es6'],
tasks:['babel']
}
}
});
require("load-grunt-tasks")(grunt);
grunt.registerTask("default", ["babel", "watch"]);
}
但是现在静态关键字给出错误,当我删除静态关键字时,构建正在通过。任何想法如何解决这个问题。 grunt-babel 过时了吗?
这是我的 packahe.json 的样子 -
{
"name": "babeles6",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"grunt": "~0.4.2",
"grunt-babel": "^5.0.1",
"grunt-contrib-watch": "^0.6.1",
"load-grunt-tasks": "^3.2.0"
}
}
【问题讨论】:
标签: ecmascript-6 babeljs