3

I'm trying to transpile es6 to es5 but it is not working.

My 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"]);
}

when I run grunt the file dist/app.js is the the same off app.js

Is anything wrong?

Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177
Alessander França
  • 2,697
  • 2
  • 29
  • 52
  • Possible duplicate of [Babel file is copied without being transformed](http://stackoverflow.com/questions/33440405/babel-file-is-copied-without-being-transformed) – Michał Perłakowski Nov 18 '16 at 21:19

2 Answers2

1

I found the error.

I had to intall babel-preset-es2015 : npm install -D babel-preset-es2015

and config the babel inside package.json.

{
  "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"
  }
}
Alessander França
  • 2,697
  • 2
  • 29
  • 52
1

you must create a file name .babelrc,and in the file you must write these:

{
  'presets':['es2015']
}