How to use RequireJS build profile + r.js in a multi-page project

Viewed 14095

I am currently learning RequireJS fundamentals and have some questions regarding a build profile, main files, and use of RequireJS with multi-page projects.

My project's directory structure is as follows:

httpdocs_siteroot/
    app/
        php files...
    media/
        css/
            css files...
        js/
            libs/
                jquery.js
                require.js
                mustache.js
            mains/
                main.page1.js
                main.page2.js
                main.page3.js
            plugins/
                jquery.plugin1.js
                jquery.plugin2.js
                jquery.plugin3.js
            utils/
                util1.js
                util2.js
        images/

Since this project is not a single-page app, I have a separate main file for each page (although some pages use the same main file).

My questions are:

  1. Is RequireJS even practical for projects that are not single-page?

  2. Without using the optimizer, each of my main files start with essentially the same config options:

    requirejs.config({
      paths: {
        'jquery': 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min'
      },
      baseUrl: '/media/js/',
      // etc...
    });
    require(['deps'], function() { /* main code */ });
    

    Is there a way to avoid this? Like having each main file include the same build profile without having to actually build it?

  3. Should r.js go in httpdocs_siteroot's parent directory?

  4. Is there something glaringly wrong with my app dir structure or my use of RequireJS?

2 Answers
Related