Set up project:
mkdir project
cd project
npm init -yInstall dev dependencies:
npm i --save-dev babel-cli babel-preset-latest nodemonConfigure Babel by adding the lines below to package.json:
"babel": {
"presets": [
"latest"
]
},Add some convenience scripts to package.json:
"scripts": {
"babel-node": "babel-node --presets=latest",
"start": "nodemon --exec npm run babel-node -- ./index.js",
"build": "babel src -d dist"
},To start the Node.js REPL:
npm run babel-nodeTo start the app in development mode (letting Babel interpret ES6 code):
npm startTo build the ES5 code in the build directory from the ES6 code in the src directory:
npm buildnpm install --save-dev mocha chaiAdd this line to the scripts section in package.json:
"scripts": {
...
"mocha": "mocha --compilers js:babel-register",
"test": "mocha --compilers js:babel-register --recursive ./test/"
}Create a new directory called test:
mkdir testMinimal test (to save e.g. as test/test.js):
'use strict'
import { expect } from 'chai'
describe('test', function () {
it('should pass', function () {
expect('string').to.be.a('string')
})
})