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