cujojs / curl

curl.js is small, fast, extensible module loader that handles AMD, CommonJS Modules/1.1, CSS, HTML/text, and legacy scripts.
https://github.com/cujojs/curl/wiki
Other
1.89k stars 216 forks source link

Adding files which include a define with the "js!" plugin cause any next module load to fail. #173

Closed guifromrio closed 11 years ago

guifromrio commented 11 years ago

Hey.

Thanks for the wonderful plugin, first of all.

So, I realize I'm using it in a really unordinary fashion, but by many reasons I really need the resource-loading capabilities of curl, without the AMD module features (!).

What I'm trying to do is including lots of libs, for example:

lib = [
    "js!lib/knockout/knockout-2.2.1-no-amd.js!order",
    "js!lib/radio.min-no-amd.js!order",
    "js!lib/jquery/jquery-1.8.3.min-no-amd.js!order",
    "js!lib/jquery/jquery.meio.mask.min.js!order",
     (...)
]

and afterwards

curl(config).next(css).next(lib).then(callback) (...)

However, I would only like KO, Radio and jQuery to export their normal global variables!

This cannot be achieved because an error pops about "multiple anonymous defines".

How can I achieve what I want, i.e., ignoring they are "AMD compliant" and just have them behave "normally"?

Thanks for any help

unscriptable commented 11 years ago

Have you looked at LABjs? curl.js is an AMD and CJS module loader. it has some features to help load legacy javascript files, but it's probably not going to be your best solution if you want to continue to use non-modular javascript. :)

unscriptable commented 11 years ago

Closing this issue. If you change your mind and want to switch over to AMD or CJS, please re-open. :)

guifromrio commented 11 years ago

Actually, I found a "solution" (hack) which is a good enough compromise for me:

window.escapeDefine = window.define
curl(config)
  .next(css)
  .then(-> window.define = undefined)
  .next(lib)
  .then(-> window.define = window.escapeDefine)
  .next(templates)
  .then(templatesCallback, errorCallback)

Just thought I should share for anyone with similar needs.