Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding require.js in optimized script

RequireJS has a nice feature to optimize a JS project into one single script (let's call it foo.js).

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

Can I make RequireJS embed itself inside the foo.js in a proper way? Would concatenating files be acceptable?

like image 630
Warren Seine Avatar asked Oct 11 '12 15:10

Warren Seine


1 Answers

Yep, the maintainer of RequireJS has put out a project just for that, almond.

I haven't used it, but from the description:

"Some developers like to use the AMD API to code modular JavaScript, but after doing an optimized build, they do not want to include a full AMD loader like RequireJS, since they do not need all that functionality. [...] By including almond in the built file, there is no need for RequireJS. "

like image 128
Waxen Avatar answered Oct 07 '22 17:10

Waxen