Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devise pattern for both AMD & <script> loading with r.js optimization #3

Closed
anodynos opened this issue Dec 2, 2012 · 1 comment
Closed

Comments

@anodynos
Copy link
Owner

anodynos commented Dec 2, 2012

Check anodynos/uBerscore#1 & https://groups.google.com/forum/?fromgroups#!topic/requirejs/NJ8A8SIffW0

With https://github.com/anodynos/uBerscore as an example, I want to have a single optimized build, as a single uBerscore.js that runs both:

  1. as <script> (needing a global _ been loaded before). Its exporting _B as a global.

OR

  1. as an AMD inclusion, it returns it self and (optionally) exports global.

I decided to use almond.js to achieve this 2-fold single build.

For the 1st case to work, since I don’t want to include ‘lodash’ in the build I tricked build.js to {paths: { lodash: "get_global_lodash" }} where get_global_lodash.js simply returns the global window._ . (example https://github.com/anodynos/uBerscore/blob/master/source/examples/uBerscoreExample_almondJS_noAMD.html)

The 2nd case, ironically, is more complicated to me. If I use the above ‘get_global_lodash’ trick, and since inside almond fake-loader, how can I load the real ‘lodash’?

The only way I have found so far is to use {shim : {uBerscore: { deps: ['lodash'], exports: "_B" }}, that loads ‘lodash’ from the ‘external ‘ requirejs. Example https://github.com/anodynos/uBerscore/blob/master/source/examples/uBerscoreExample_almondJS_AMD.html

It works fine but it’s a shame to need shim to run AMD code!

Does anyone have an idea of what pattern to use ? I want to avoid having two sep builds (AMD and plain).

Any help will be greatly appreciated, as I am looking to generalize it enough and include it to uRequire (https://github.com/anodynos/uRequire), the Universal Module Converter I am also developing.

@ghost ghost assigned anodynos Dec 2, 2012
anodynos added a commit that referenced this issue Jan 18, 2013

Verified

This commit was signed with the committer’s verified signature.
msfjarvis Harsh Shandilya
@anodynos
Copy link
Owner Author

Solved in v0.3 4b9fda1

anodynos added a commit that referenced this issue Sep 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant