2

main.js below

requirejs.config({
    baseUrl: ".",
    shim: {
        p: ['jquery']
    },
    paths: {
        'jquery': '//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min',
        'p': 'p'
    }
});

require(['jquery', 'c'], function ($) {
    console.log($)
});

c.js below

define(['p'], function () {
    return {};
});

build.js below

({
    baseUrl: ".",
    name: "main",
    out: "main-built.js",
    optimize: "none",
    mainConfigFile: 'main.js'

})

p.js

$('body').html('p!');

Build command:

node path/to/r.js -o ./build.js

This is my index.html

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>

<script src="../app/libs/requirejs/require.js" data-main="main-built"></script>

</body>
</html>

And I got the error when tried to open this file:

Uncaught ReferenceError: $ is not defined 

Is it possible to fix this problem?

Thanks!

UDP1: I added this to build.js, but it doesn't work

paths: {
        jquery: "empty:"
    }
2
  • After you add the paths config, does it fail in exactly the same way as before? Also, are you sure that you are using the new version of your built file? If you are testing using a browser that loads files right off your local filesystem you can run into caching issues. (Clearing your cache ensures you're loading the latest files.) Commented Dec 6, 2013 at 13:13
  • Yes, it fail exactly the same way as before. I used 2.1.9 version of r.js and requirejs. I used nginx for local http server and I cleared the browser cache. Commented Dec 9, 2013 at 6:11

1 Answer 1

1

Use an "empty:" path in your build config:

({
    baseUrl: ".",
    name: "main",
    out: "main-built.js",
    optimize: "none",
    mainConfigFile: 'main.js',
    paths: {
        jquery: "empty:"
    }
})
Sign up to request clarification or add additional context in comments.

Comments

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.