How does browserify bundle a universal module
Asked Answered
R

2

5

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?

Rustle answered 11/5, 2015 at 14:31 Comment(3)
What does "browserify can consume UMD modules by means of transforms" mean?Hardtack
deamdify like this transform allows you to use AMD module with browserifyRustle
Right, but you shouldn't need any transform to use a UMD module with browserify, although you may need to noParse it.Hardtack
H
4

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

browserify('./entry.js', {
  standalone: 'moduleName',
})
Hardtack answered 11/5, 2015 at 21:3 Comment(2)
isn't it that standalone exposes the module to global namespace?Rustle
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.Hardtack
N
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.

Nomarchy answered 11/5, 2016 at 14:7 Comment(1)
Also, JMM's comment is also correct, and is a way you'd configure it in a build script.Nomarchy

© 2022 - 2024 — McMap. All rights reserved.