【问题标题】:grunt babel is not working咕噜巴贝尔不工作
【发布时间】:2016-02-11 08:28:10
【问题描述】:

我正在尝试将 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"]);
}

当我运行 grunt 时,文件 dist/app.js 与 app.js 相同

有什么事吗?

【问题讨论】:

标签: javascript gruntjs babeljs grunt-babel


【解决方案1】:

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

{
  'presets':['es2015']
}

【讨论】:

    【解决方案2】:

    我发现了错误。

    我必须安装 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"
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-05
      • 1970-01-01
      • 1970-01-01
      • 2015-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多