Friday, 26 May 2017

Properly exporting from Node using Browserify

I often see this code on the beginning of "exported" node apps:

(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Foo = ...

For example, here: https://gist.github.com/mridgway/20c16742cd1d745c86d6

But if I use Browserify to made an export manually, like shown blow, this part is missing. I do it like this:

browserify somefile.js -o bundle.js

Could you tell where this code (long line in the first block) came from? From Node of from Browserify? And how to set up Node (or, respectively, Browserify) to "get" this code on export.



via james

No comments:

Post a Comment