Jeremy Smith
Jeremy Smith

Reputation: 15069

Is it possible to have multiple require.js projects included in one html file?

I would like to do something like this:

<script data-main="/js/D4/build/mainD4" src="/js/D4/build/require.js"></script>
<script data-main="/js/main" src="/js/require.js"></script>

I could just build the first file, and the include the build js file in /js/main, but it would be much faster to be able to do development on both projects side by side without having to build all of the time. Right now when I try this, mainD4 builds and then nothing happens with the js/main file.

Upvotes: 6

Views: 1157

Answers (1)

Jeremy Smith
Jeremy Smith

Reputation: 15069

Just found the answer here: https://groups.google.com/forum/?fromgroups#!topic/requirejs/YWFdgYSU2f4

<script src="scripts/require.js" data-main="scripts/main"></script>
<script>
require(['scripts/another/main']);
</script>

or

<script src="scripts/require.js" data-main="scripts/main"></script>
<script>
(function(){
  var req = require.config({baseUrl:'scripts/another'});
  req(['main']);
}());
</script>

Upvotes: 6

Related Questions