Using Require.js without data-main

Levi McCallum picture Levi McCallum · Oct 12, 2012 · Viewed 18.6k times · Source

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.

Answer

Waxen picture Waxen · Oct 12, 2012

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>