How to publish a module written in ES6 to NPM?
Solution 1:
The pattern I have seen so far is to keep the es6 files in a src
directory and build your stuff in npm's prepublish to the lib
directory.
You will need an .npmignore file, similar to .gitignore but ignoring src
instead of lib
.
Solution 2:
I like José's answer. I've noticed several modules follow that pattern already. Here's how you can easily implement it with Babel6. I install babel-cli
locally so the build doesn't break if I ever change my global babel version.
.npmignore
/src/
.gitignore
/lib/
/node_modules/
Install Babel
npm install --save-dev babel-core babel-cli babel-preset-es2015
package.json
{
"main": "lib/index.js",
"scripts": {
"prepublish": "babel src --out-dir lib"
},
"babel": {
"presets": ["es2015"]
}
}