I'm trying to follow a series of examples to learn ES6, but I can't get it to transpile correctly.
In my case I use the following line to do it
babel --watch index.js --out-file index_ES5.js
My file .eslintrc
has the following configuration
{
"parser": "babel-eslint",
"plugins": ["import"],
"extends": "airbnb",
"env": {
"node": true,
"es6": true,
"browser": true
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": false
}
},
"rules": {
// evita que marque error al usar console
"no-console": 0,
// permite usar variables con _
"no-underscore-dangle": 0,
// máximo de línea: 99
"max-len": [1, 99, 2],
// obliga a usar punto y coma
"semi": [1, "always"],
// obliga a usar const sobre let
"prefer-const": 2,
// obliga a definir llaves en if/else
"curly": [2, "all"],
// prefiere === a ==
"eqeqeq": [2, "allow-null"],
"no-shadow": 1,
// no exige que las funciones como callbacks
// tengan un nombre
"func-names": 0,
// prefiere apóstrofe a comillas
// y también para template literal
"quotes": [
2,
"single",
{
"allowTemplateLiterals": true
}
],
// previene múltiples líneas en blanco
"no-multiple-empty-lines": [ 2, {
"max": 1,
"maxEOF": 0,
"maxBOF": 0
}],
// no activa el warning en parámetros rest
"no-unused-vars": ["warn", {
"ignoreRestSiblings": true
}],
"linebreak-style": "off"
},
"settings": {
"node": {
"extensions": [
".js"
],
"moduleDirectory": [
"node_modules",
"./"
]
},
"import/resolver": {
"node": {
"extensions": [
".js"
],
"moduleDirectory": [
"node_modules",
"./"
]
}
}
}
}
To compile
ES6
a youES5
need to install apreset
, specifically:Install
babel-preset-es2015
, for example, vianpm
:Then you can use it:
Via
CLI
Via
.babelrc
:You must create a file named
.babelrc
and containing:The latter being the most recommended, since it would prevent you from having to indicate the
presets
each time you executebabel
PS : The file
.eslintrc
is for theESLint
( syntax error checker and highlighter ).