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?
Asked
Active
Viewed 2,846 times
5
-
What does "browserify can consume UMD modules by means of transforms" mean? – JMM May 11 '15 at 21:03
-
`deamdify` like this transform allows you to use AMD module with browserify – hjl May 12 '15 at 01:54
-
Right, but you shouldn't need any transform to use a *UMD* module with browserify, although you may need to `noParse` it. – JMM May 12 '15 at 12:06
2 Answers
4
If you want to build a UMD module with browserify use the standalone
option. Like:
browserify('./entry.js', {
standalone: 'moduleName',
})

JMM
- 26,019
- 3
- 50
- 55
-
-
2`standalone` creates a UMD module. If the code doesn't detect that it's in an AMD or CommonJS environment, it sets a global variable. – JMM May 12 '15 at 12:05
4
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.

Dean Radcliffe
- 2,194
- 22
- 29
-
Also, JMM's comment is also correct, and is a way you'd configure it in a build script. – Dean Radcliffe May 11 '16 at 14:10