Transpiling ES6 to ES5 using Babel

Asked

Viewed 242 times

0

I have a package.json file set up to take all js files from a directory and join them into a new file, transpiling to ES5. However, it is only creating a new file and unifying all js files from the specified directory. It is not converting to ES5. I don’t know what’s missing from the package.json file, if you can help me. Follow the code:

{
  "name": "farmafam",
  "version": "1.0.0",
  "description": "",
  "babel": {
    "presets": ["es2015"]
  },
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "babel": "babel ../js/modulos/js-es6 --watch --out-file ../js/modulos/modulos.js"
  },
  "author": "KM2",
  "license": "ISC",
  "devDependencies": {
    "babel-cli": "^6.14.0",
    "babel-preset-es2015": "^6.14.0"
  }
}
  • I doubt that Babel will search for presets in package.json. Tests with --presets es2015 in charge, that is to say: "babel": "babel ../js/modulos/js-es6 --presets es2015 --watch --out-file ../js/modulos/modulos.js"

  • I made the change and it shows the following error: couldn’t find preset "es2015" relative to directory ".. js modulos js-es6". :/

  • Maybe the order is wrong, test on the console directly babel --presets es2015 --watch ../js/modulos/js-es6 ../js/modulos/modulos.js. I have so often to compile.

  • He says that the es2015 does not exist. See: "es2015 doesn’t exist". I did several tests here and found out that when I play the js-es6 folder into my npm folder with the Babel modules installed, I change the paths in the package.js file. It works perfectly. But I thought about leaving it separate by organization. Like, inside the npm folder will be all the modules I will use in the project. If you mix it all up, it gets a little messy. :/

  • It’s not a direct answer to your problem, but try to use the webpack as Babel’s module bundler, which will be a lot easier. If you already use it below 2 webpack usage links with Babel. link1 Link2

  • @Alan take a look here: http://answall.com/a/146397/129 I will try to simulate your case later and see if I can reproduce your problem.

  • @Alan you created the file .babelrc ?

  • What solved my problem was leaving the js-es6 files together with the Babel modules and package.json. Putting them together he compiles them right. But when I separate it only joins the js and n converts.

  • "Babel": "Babel js-es6 --watch --out-file modulos.js"

Show 4 more comments

1 answer

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.