Matthew
Matthew

Reputation: 2310

Using one RequireJS project within another RequireJS project

I have a RequireJS project I am working on with the following structure: Project/ index.html
src/ main.js projectcomponent.js lib/ require.js

main.js is the entry point of the Require application and has the following require.config inside it:

require.config
    baseUrl: "./"

main.js returns an object.

I want to use this entire project as a module inside another RequireJS project. I attempted to use r.js (the RequireJS optimisation tool) to reduce the project to a single file, which worked - but as it relied on RequireJS, its config conflicted with the config of the parent project I wanted to use this project as a module for.

How can I use one RequireJS project as a module inside another RequireJS project?

Upvotes: 1

Views: 75

Answers (1)

imcg
imcg

Reputation: 2649

You can get round this by using almond (https://github.com/jrburke/almond) to replace the require.js dependency, making the first project a fully encapsulated single file.

There's some further explanation and relevant links on the RequireJS site: http://requirejs.org/docs/faq-optimization.html#wrap

Upvotes: 1

Related Questions