4

I'm optimizing my requirejs app along with backbone and jquerymobile, the following is my file structure:

/application
    /app
       /models
       /views
       /collections
    /scripts
       main.js
       text.js
       /assets
            backbone.js
       /libs
            /jquery
                /jquery.js
                /jquery-mobile.js
 app.js
 r.js
/public
    /css
        /style.css

In the console, I tried to run to ff command:

node ../r.js -o name=main out=../build.js baseUrl=. paths.models=../app/models paths.app=../app

I made sure that paths are well defined and properly working except with this error( this is what I am getting when running the command):

Tracing dependencies for: main
Error: Module loading did not complete for: jquery
    at Function.traceDependencies (/home/dunhak/public_html/my_path/etc/application/r.js:15117:19)

Thank you so much!

0

1 Answer 1

4

Some of this will depend on the order you load your scripts. Is jQuery loaded before require.js or the other way around?

The last few lines of jQuery may hold the clue to a solution:

if ( typeof define === "function" && define.amd && define.amd.jQuery ) {
    define( "jquery", [], function () { return jQuery; } );
}

My guess is that you're doing something like:

var $ = require('jquery'); //lower-case Q

personally, I've been doing:

var $ = require('jQuery'); //upper-case Q

this all may depend on your require.config -- I use something like:

require.config({
    baseUrl: "/js",

    paths : {
        jQuery: 'lib/jquery-1.7.1.min'
        //, etc...
    }
})

Another thing to think about: You may not want jQuery included as part of your optimized output -- instead, load the pre-minified version from a CDN (etc). In that case, you need to exclude the jquery module as described here: http://requirejs.org/docs/jquery.html

modules: [
    {
        name: "main",
        exclude: ["jquery"]
    }
]
Sign up to request clarification or add additional context in comments.

1 Comment

That's a great help dude!. I saved a lot of time. I realized that it's better if I 'empty' the paths for the libraries that are hosted via CDN, in this case, jQuery. What I did is, I added paths.jquery=empty in my command. Thanks a lot :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.