Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does browserify bundle a universal module

Tags:

browserify

umd

I know browserify can consume UMD modules by means of transforms, but when I want to build a lib using browserify, how can I build an UMD module? Is there any transform I can use?

like image 860
hjl Avatar asked May 11 '15 14:05

hjl


2 Answers

If you want to build a UMD module with browserify use the standalone option. Like:

browserify('./entry.js', {
  standalone: 'moduleName',
})
like image 148
JMM Avatar answered Oct 14 '22 01:10

JMM


From the CLI: browserify -s NameOfModule

This creates a standalone module exposed under the name of your choosing.

Utilize by loading the output file in a browser and access via window.NameOfModule, or see RequireJS docs on how to use it that way.

like image 22
Dean Radcliffe Avatar answered Oct 14 '22 03:10

Dean Radcliffe