Update (Jan 2019): This article was written with an outdated version of Babel (Babel 5). Also, consider replacing Browserify with something more modern like Rollup.
With this technique, there's no need to maintain a full new directory of compiled files... just one pre-built
Put your actual main entry point as, say,
./lib/index.js. Then create an entry point
./index.js like this for development:
Set up a compliation script in the prepublish hook:
For CoffeeScript support, use coffeeify for CoffeeScript (
-t [ coffeeify -x .coffee ]).
-s- standalone (uses a UMD wrapper)
--bare- don't stub node builtins
-t- define transformations to use
For packages targeting Node.js, use
--node --no-bundle-external. This will disable browser-field resolution in package.json and not bundle node_modules.
package.json to the precompiled version:
npm publishis called, the pre-built version (dist/js2coffee.js) gets built
require('js2coffee')will point to the
require('../index')in your tests will point to the source version
require('js2coffee/index')from other packages
For babeljs, I recommend using
--loose for libraries that will target legacy IE.