简体   繁体   中英

Condense ES2015/CommonJS Modules to One CommonJS Module with Gulp

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'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM