Reputation: 9965
I set the data-main for Requirejs and according to the documentation that should set the baseUrl for all my script files. But this is not the case. My folder structure is this:
Home/Index.html
Content/scripts/main.js
Content/scripts/libs/require/require.js
Content/scripts/libs/jquery/require_jquery.js
Content/scripts/libs/jquery/jquery-1.7.1.mins.js
Here is the script tag in my Index.html:
<script data-main="/PAWS/Content/scripts/main.js" src="/PAWS/Content/scripts/libs/require/require.js" type="text/javascript"></script>
I would assume it would set my baseUrl to /PAWS/Content/scripts/ but its not working for me. In my main.js I do this:
require(
{ paths:
{ jquery: 'libs/jquery',
knockout: 'libs/knockout'
}
},
['jquery/require_jquery'],
function ($) { .... }
);
In my require_jquery.js file I do this:
define(["libs/jquery/jquery-1.7.1.min.js"], function () {
return jQuery;
});
But I get a 404 error saying that:
GET http://localhost/PAWS/Home/libs/jquery/jquery-1.7.1.min.js 404 NOT FOUND
You see.. my baseUrl should be /PAWS/Content/scripts... But it totally ignores my data-main attribute setting and just resolves /PAWS/Home/ to be the baseUrl. What am I doing wrong?
Upvotes: 9
Views: 3961
Reputation: 2055
From the RequireJS API docs:
However, if the dependency name has one of the following properties, it is treated as a regular file path, like something that was passed to a
<script src="">
tag:
- Ends in ".js".
- Starts with a "/".
- Contains an URL protocol, like "http:" or "https:".
From this, it appears that your explicit ".js" on the end of libs/jquery/jquery-1.7.1.min.js
is confounding your path re: baseUrl. Try libs/jquery/jquery-1.7.1.min
instead.
Upvotes: 10