question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a way to build standalone bundles without UMD

See original GitHub issue

Currently the --standalone flag wraps the whole code in a silly UMD wrapper. This isn’t really helpful if you just want the standalone to register it self always as global. There should be away to turn UMD off, or provide your own template instead.

Issue Analytics

  • State:open
  • Created 9 years ago
  • Reactions:2
  • Comments:10

github_iconTop GitHub Comments

2reactions
aldendanielscommented, May 5, 2015

Hey @jstayton - sure thing.

All Browserify bundles are defined within a wrapping closure so nothing in your bundle will leak out. The issue is that JavaScript doesn’t currently provide a good way to keep global variables from “leaking in”. In other words, your code and bundled dependencies can reference global variables that someone else defined.

Imagine that your script is deployed to a site that’s already using AMD. AMD defines a global define function. No problem - that shouldn’t affect your code. Now imagine that your code includes a UMD dependency that goes looking for the existence of define to decide whether it should behave as an AMD or CommonJS script. Now you have a problem, since your dependency will convert itself to AMD in this environment.

Ideally JavaScript would provide a way for a closure to “whitelist” which global variables it could access - window for example. Since this feature doesn’t exist, we instead need to blacklist the global variables the closure doesn’t want access to by redefining them within the closure.

When (and only when) you use the --standalone flag, Browserify does exactly this for define, module, and exports.

1reaction
aldendanielscommented, Jun 16, 2015

@3rd-Eden, you can achieve your desired behavior today using the https://github.com/primus/deumdify plugin. It’s a hack, but a useful and well-maintained one. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Standalone Builds - SurviveJS
To make a bundle for your own library, you need to use a bundler, such as webpack, Rollup, or Parcel. How Bundlers Work#....
Read more >
angular2 how to bundle a UMD module without ng2 ...
Step 2: Use rollup to create UMD bundle. const pkg = require('./package.json') const rollup = require('rollup'); gulp.task('rollup:module', ...
Read more >
A way to build Angular plugin with AOT and standalone deploy
In this article i will show you how to build angular UMD plugin with AOT (Ahead-of-Time) support and standalone deploy.
Read more >
Standalone Browserify Builds - Forbes Lindesay
Browserify now supports standalone builds thanks to integration with my umd (universal module definition) library.
Read more >
JavaScript Data Grid: Building Applications With AG ... - AG Grid
If however you do not need all the features provided by either package (Community or Enterprise) then it's possible to create your own...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found