thlorenz / browserify-shim

📩 Makes CommonJS incompatible files browserifyable.
MIT License
933 stars 87 forks source link

configuration for global variable with no script name #214

Closed tjaartvdwalt closed 8 years ago

tjaartvdwalt commented 8 years ago

Hi, I need someone please point me in the right direction.

It seems to be a really clean solution to expose global variables through the shim config.

Something I do not completely understand is how the script defined in the <scripts> tag is linked to the browserify-shim configuration? Does that happen through the script filename?

In the documentation example, does the "three" in the "browserify-shim" config match the file three.min.js in the <script> tag?

If this understanding is correct, how do I link scripts that do not explicitly have a filename? A good example for me would be the Google Maps API.

Here is an example of what I would like to achieve:

<script type="text/javascript" src="https://maps.google.com/maps/api/js?key=xxxxxxx&libraries=places"></script>
  "browserify-shim": {
    "?": "global:?"
  },
bendrucker commented 8 years ago

Does that happen through the script filename?

No, browserify-shim doesn't load your scripts when you use globals. Script loading is left up to you. You're just telling it that the script publishes itself as window.THREE.

how do I link scripts that do not explicitly have a filename?

Same deal, you use globals and load yourself. But you should try load-google-maps instead of shimming.

Does this answer your question?

tjaartvdwalt commented 8 years ago

Thanks for the quick answer. I will have a look at load-google-maps.

Just to close of this issue, I do not have total clarity yet. If we look at the example:

"browserify-shim": {
    "three": "global:THREE"
  }

How does browserify-shim know which script the key "three" matches to?

bendrucker commented 8 years ago

How does browserify-shim know which script the key "three" matches to?

It doesn't. It's your job to add the tag so window.THREE is defined before your bundle is evaluated.

tjaartvdwalt commented 8 years ago

ah ok, now I get it. Thanks