Skip to content

Instantly share code, notes, and snippets.

@mzabriskie
Last active July 17, 2017 16:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzabriskie/29767feb54527a7457f91f1af662bc1b to your computer and use it in GitHub Desktop.
Save mzabriskie/29767feb54527a7457f91f1af662bc1b to your computer and use it in GitHub Desktop.
Releasing ES6 node modules to npm
build/
node_modules/

My approach for releasing a node module to npm that uses ES6 syntax.

This uses babel to generate a non-ES6 version of the source when a new version is released, then only publishes the built source.

$ npm version <newversion> -m "Releasing %s"
$ npm publish
#!/bin/bash -e
babel=./node_modules/.bin/babel
# Clean old build
rm -rf build/
# Transpile ES6
$babel index.js -d build/ --presets babel-preset-es2015
# Copy package & README
cp README.md build/
node -p 'p=require("./package");p.scripts=p.devDependencies=undefined;JSON.stringify(p,null,2)' > build/package.json
{
"main": "index.js",
"files": ["build/"],
"scripts": {
"test": "karma start --single-run",
"build": "./build",
"preversion": "npm test",
"postversion": "git push && git push --tags",
"prepublish": "npm run build"
},
"devDependencies": {
"babel": "^6.5.2",
"babel-cli": "^6.9.0",
"babel-core": "^6.9.0",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.9.0",
"karma": "^0.13.22",
"karma-cli": "^1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment