Frage

I'm trying to build my single page application that uses Require.js, AMD style modules.

I already configured all the dependencies, paths and shims in my init.js file that runs first and then calls my main.js file.

Here is my init.js file :

(function() {
    'use strict';
    var me = this;
    me.require.config({

        deps: ['backbone.marionette', 'main'],

        shim: {
            jquery: {
                exports: 'jQuery'
            },
            underscore: {
                exports: '_'
            },
            backbone: {
                deps: [
                    'underscore',
                    'jquery'
                ],
                exports: 'Backbone'
            },
            'backbone.marionette': {
                deps: ['jquery', 'underscore', 'backbone'],
                exports: 'Marionette'
            }
        },

        paths: {
            jquery: '../lib/jquery/dist/jquery.min',
            html5shiv: '../lib/html5shiv/html5shiv.js',
            underscore: '../lib/underscore/underscore-min',
            backbone: '../lib/backbone/backbone',
            'backbone.marionette': '../lib/backbone.marionette/lib/core/amd/backbone.marionette.min',
            'backbone.wreqr': '../lib/backbone.wreqr/lib/amd/backbone.wreqr.min',
            'backbone.babysitter': '../lib/backbone.babysitter/lib/amd/backbone.babysitter.min',
            text: '../lib/requirejs-text/text'
        }

    });
}).call(this);

and here is my r.js build config file :

({
    baseUrl: '../../development/js',
    optimize: 'closure',
    paths: {
        requireLib: '../lib/requirejs/require'
    },
    mainConfigFile: '../../development/js/init.js',
    out: '../../distribution/main-build.js',
    include: ['requireLib']
})

When I build, I only get Require.js inlined in my main-build.js file.

R.js doesn't follow the deps property defined in the require.config for some reason.

  • Any ideas on how to get a single file containing my Backbone.js / Marionette.js files and the dependencies described in the require.config found in the init.js file ?

Thanks in advance !

War es hilfreich?

Lösung

I wonder if it is the way you defined your config. Is there any reason for the init.js as opposed to just putting the require.config in main? It seems unnecessary to create an anonymous function just to encapsulate it.

From the example r.js build file:

The first requirejs({}), require({}), requirejs.config({}), or require.config({}) call found in that file will be used.

What has always worked for me is to follow the more standard method of calling require.config() inside main.js

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top