Skip to content

Instantly share code, notes, and snippets.

@witt3rd
Last active June 20, 2018 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save witt3rd/97b23f0fb462ca440812cc2e0b31b0bd to your computer and use it in GitHub Desktop.
Save witt3rd/97b23f0fb462ca440812cc2e0b31b0bd to your computer and use it in GitHub Desktop.

node

https://nodejs.org/en/

OSX

brew install node

npm

https://www.npmjs.com/

OSX

installed as part of node

update

npm i -g npm@latest

babel

https://babeljs.io/docs/setup#installation

npm i -D babel-cli babel-preset-env babel-watch

Update the package.json scripts to include:

"scripts": {
    "build": "babel src -d dist",
    "start": "babel-watch src"
  },

Add a .babelrc file:

{
  "presets": ["env"]
}

babel-node

babel-node is a CLI that works exactly the same as the Node.js CLI, with the added benefit of compiling with Babel presets and plugins before running it.

npm install --save-dev @babel/core @babel/node
"scripts": {
  "start": "babel-node src"
}

babel-watch

Reload your babel-node app on JS source file changes. And do it fast.

npm install --save-dev babel-watch
"scripts": {
  "start": "babel-watch src"
}

Code formatting

VS Code

https://www.39digits.com/configure-prettier-and-eslint-in-visual-studio-code/

Prettier and pre-commit hooks

We also configure Prettier to ensure proper format on git commit.

npm i -D prettier lint-staged husky

Update the package.json to include:

{
  "scripts": {
    "precommit": "lint-staged"
  },
  "lint-staged": {
    "*.{js,json,css,md}": ["prettier --write", "git add"]
  }
}

Scaffolding

node-oss

A node project with Babel, ESLint, Prettier, Jest, ...

npm install --global yo generator-node-oss
yo node-oss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment