Skip to content

Instantly share code, notes, and snippets.

@rjjakes
Last active December 2, 2017 20:48
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 rjjakes/629591971a9fe2d4ce3ca939dadbce64 to your computer and use it in GitHub Desktop.
Save rjjakes/629591971a9fe2d4ce3ca939dadbce64 to your computer and use it in GitHub Desktop.
Create and publish an ES6 npm module using yarn and babel.

Create and publish an ES6 npm module using yarn and babel.

Create a new npm project:

npm init 

Create source/ and distribution/ directories/

mkdir source && mkdir distribution

Create source/index.js and source/test.js files.

Install babel:

yarn add babel-cli@6 babel-preset-es2015@6 --dev 

Add the following to your package.json

  "scripts": {
    "build": "babel source --presets babel-preset-es2015 --out-dir distribution",
    "test": "node ./distribution/test.js",
    "prepare": "yarn run build"
  },

Now compile and test your code:

yarn run build && yarn run test 

Set the entry point of your module to the distribution code by adding this to package.json:

  "main": "./distribution/index.js",

Publish your module to npm:

npm publish

Note that the "prepare" command in package.json will be run each time you yarn or npm publish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment