-7

Can Anyone help me to setup Babel so that my latest ES6, ES7 code runs on NodeJS ?

Sumer
  • 2,687
  • 24
  • 24

1 Answers1

0

Use the below Package JSON file and install required modules

{
  "name": "babelSetup",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "nodemon --exec babel-node src/index.js",
    "build": "babel src --out-dir dist",
    "serve": "node dist/index.js"
  },
  "devDependencies": {
    "@babel/cli": "^7.1.5",
    "@babel/core": "^7.1.6",
    "@babel/node": "^7.0.0",
    "@babel/preset-env": "^7.1.6",
    "nodemon": "^1.18.7"
  }
}

use below .babelrc file

{
  "presets": ["@babel/preset-env"]
}

if you look at the scripts commands you can learn that all source scripts should be kept in src folder, generated files should be kept on dist folder and the entry point script should be named index.js. Please change as per your need. I had a tough time searching all this so thought of sharing this on stackoverflow :)

Sumer
  • 2,687
  • 24
  • 24