Skip to content

Instantly share code, notes, and snippets.

@og24715
Forked from sam-artuso/setting-up-babel-nodemon.md
Last active April 16, 2018 00:53
Show Gist options
  • Save og24715/fe1c0d3c91e7b0f8f5d1b1a7659b1427 to your computer and use it in GitHub Desktop.
Save og24715/fe1c0d3c91e7b0f8f5d1b1a7659b1427 to your computer and use it in GitHub Desktop.
Setting up Babel and nodemon

Setting up Babel and nodemon

Inital set-up

Set up project:

mkdir project
cd project
yarn init -y

Install dev dependencies:

yarn add -D babel-cli babel-preset-env nodemon

Configure Babel by adding the lines below to package.json:

"babel": {
  "presets": [
    "env"
  ]
},

Scripts

Add some convenience scripts to package.json:

"scripts": {
  "babel-node": "babel-node --presets=env",
  "start": "nodemon --exec npm run babel-node -- src/",
  "build": "babel src -d dist"
},

To start the Node.js REPL:

yarn babel-node

To start the app in development mode (letting Babel interpret ES6 code):

yarn start

To build the ES5 code in the build directory from the ES6 code in the src directory:

yarn build

Adding in Mocha and chai

yarn add -D mocha chai

Add 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 test

Minimal test (to save e.g. as test/test.js):

import { expect } from 'chai'

describe('test', () => {
  it('should pass', () => {
    expect('string').to.be.a('string')
  })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment