Require.js nesting in optimized script

RequireJS has the nice opportunity to optimize a JS project in one single script (let it be foo.js ).

If I include foo.js , I get: Uncaught ReferenceError: define is not defined . The error goes away if I add require.js to foo.js because define is defined by RequireJS. I do not want my library users to have to do this in order to use it.

Can I get RequireJS to properly inject itself inside foo.js ? Will file concatenation be acceptable?

+7
source share
1 answer

Yes, the RequireJS developer has released a project for this, almond .

I did not use it, but from the description:

"Some developers like to use the AMD API to encode modular JavaScript, but after creating an optimized assembly, they don’t want to include the full AMD loader, for example RequireJS, because they don’t need all these functions. [...] Including almonds in the embedded file, there is no need RequireJS. "

+6
source

All Articles