7

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?

1 Answer 1

6

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. "

Sign up to request clarification or add additional context in comments.

1 Comment

I had never heard of it. Sounds like the perfect solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.