I am trying to set up folders for require.js and I am just having errors.
Here is my folder structure:
Web folder
--default.html
--[Scripts]
----main.js
----require-cfg.js
----require.js
----[lib]
------jquery1-9.1.js
my require-cfg.js
var require = ({
baseUrl: 'Scripts',
paths: {
jquery: '/lib/jquery-1.9.1'
}
});
In my main.js:
require(["require-cfg"], function (core) {
});
in my default.html
<script src="Scripts/require-cfg.js"></script>
<script src="Scripts/require.js"></script>
<script src="Scripts/main.js"></script>
I have a function in the main.js that uses jquery syntax. When I run the web app, I am getting the error"
JavaScript runtime error: '$' is undefined
can anyone direct me on what I am doing wrong??
THanks!!
-- I figured out that By default, jQuery registers itself using the global functions "$" and "jQuery", even when used with AMD/RequireJS. If you want to turn off this behavior you have to call noConflict function:Correct way to implement jQuery with require.js
adding the below worked:
define('jquery-private', ['jquery'], function (jq) {
return jq.noConflict( true );
});