咕噜巴贝尔不工作

grunt babel is not working

我正在尝试将 es6 转换为 es5,但它不起作用。

我的Gruntfile.js

module.exports = function(grunt){
    "use strict";

    grunt.loadNpmTasks('grunt-babel');

  grunt.initConfig({
    "babel": {
      options: {
        sourceMap: true
      },
      dist: {
        files: {
          "dist/app.js": "app.js"
        }
      }
    }
  });

  grunt.registerTask("default", ["babel"]);
}

当我 运行 g运行t 文件 dist/app.js 是相同的 app.js

有什么问题吗?

我发现了错误。

我必须安装 babel-preset-es2015 : npm install -D babel-preset-es2015

并在 package.json.

中配置 babel
{
  "name": "babel",
  "version": "0.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "babel": {
    "presets": [
      "es2015"
    ]
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-cli": "^6.1.18",
    "babel-preset-es2015": "^6.1.18",
    "babelify": "^7.2.0",
    "grunt": "^0.4.5",
    "grunt-babel": "^6.0.0",
    "grunt-browserify": "^4.0.1",
    "grunt-contrib-watch": "^0.6.1",
    "load-grunt-tasks": "^3.3.0"
  }
}

你必须创建一个文件名.babelrc,并且在文件中你必须写这些:

{
  'presets':['es2015']
}