I am writing an library in TypeScript that I want to compile into a single CommonJS module. With browserify
, I could give it a single file, have that file run through tsify
and babelify
to produce one file that had all of the files combined into one. I basically want the same sort of functionality, but I need it to result in a CommonJS module to use with CommonJS-compatible systems like NodeJS instead of the browser.
I am having troubles finding an option or a plug-in that does this. Am I overlooking something?
What you are looking for is --standalone
or -s
option:
Generate a UMD bundle for the supplied export name. This bundle works with other module systems and sets the name given as a window global if no module system is found.
Using the Command Line:
browserify main.js --standalone myLib > myLib.js
Using the API:
var fs = require('fs');
var browserify = require('browserify');
var b = browserify('./main.js');
b.bundle({standalone: 'myLib'}).pipe(fs.createWriteStream(__dirname + '/myLib.js'));