Can I use Require.js in development without using the data-main
attribute to load in my initial script? ie. <script data-main="scripts/main" src="scripts/require.js"></script>
I'm finding it difficult for me to work with this attribute in my development environment.
Asked
Active
Viewed 1.9k times
33

stillmotion
- 4,608
- 4
- 30
- 36
1 Answers
52
Yep, take a look at the documentation: http://requirejs.org/docs/api.html#config
You need to call require.config() and set baseUrl. Based on your example:
<script src="scripts/require.js"></script>
<script>
require.config({
baseUrl: "scripts"
});
require( [ /*...*/ ], function( /*...*/ ) {
/*...*/
});
</script>

Waxen
- 1,792
- 2
- 27
- 27
-
1Thanks! It's a convenient way to use requireJS in a valid xhtml page as far as `data-main` was only introduced into html5. – Charles-Édouard Coste Mar 20 '14 at 11:42
-
1Just to be clear about @Charles-EdouardCoste comment, `data-main` is not an html5 property. Html5 simply allows `data-*` properties. `Data-main` is specifically searched for by require.js, i.e. here: https://github.com/requirejs/requirejs/blob/4316f8f19f981c726eb32b5335c36237e0125948/require.js#L2016 – David Baird Nov 23 '16 at 22:55
-
Yes, I was just fast-typing. Indeed, I would have written "data-*" – Charles-Édouard Coste Nov 24 '16 at 10:52