Hello people,
I'm in doubt to set up RequireJS
correctly, but I also have doubts about organizing Trees to set baseUrl
and so I'll demonstrate how I'm setting up:
.
├── index.html
├── js
│ ├── boot.js
│ ├── main.js
│ ├── noConflict.js
│ └── lib
│ ├── autosize.js
│ ├── drilldownmenu.js
│ ├── easing.js
│ └── smooth-scrollbar.js
└── vendor
├── jquery.min.js
└── require.js
This is the structure in the Project Tree and index.html
put these settings:
<script type="text/JavaScript" data-main="js/boot" src="vendor/require.js"></script>
So far the RequireJS loads the problem is to call the jQuery
, before I will show the code of the configuration boot.js
:
;(function( undefined ) {
'use strict';
requirejs.config({
baseUrl: "./js/lib",
paths: {
// Módulo jQuery
"jquery": "../../vendor/jquery.min",
// [Config] jQuery
"main": "../main"
},
shim: {
"easing": ["jquery"],
"smooth-scrollbar": ["jquery"],
"drilldownmenu": ["jquery"],
"autosize": ["jquery"]
},
map: {
"*": {
"jquery": "../noConflict"
},
"noConflict": {
"jquery": "jquery"
}
}
});
// Chamando módulo principal para iniciar a aplicação
requirejs(["main"]);
})();
When I run it works to a certain extent that is jQuery
that does not load, realize that I use a technique that is noConflict
and in it comes the problem, it says it does not recognize the TypeError: jQuery is undefined
function and when I see in the requests the module defined in paths
does not load:
IwasabletosolvetheproblemofnoConflict.js
byusingthiscodeinthefileboot.js
(FilethathastheRequireJSsettings):
;(function(undefined){'usestrict';requirejs.config({baseUrl:'js/lib',paths:{//MódulojQuery'jquery':['../../vendor/jquery.min','//code.jquery.com/jquery-3.0.0.min.js'],//Config'main':'../main'},shim:{'jquery':{exports:'$'},'easing':{deps:['jquery']},'smooth-scrollbar':{deps:['jquery']},'drilldownmenu':{deps:['jquery']},'autosize':{deps:['jquery']}},map:{'*':{'jquery':'../noConflict'},'../noConflict':{'jquery':'jquery'}}});//Chamandomóduloprincipalparainiciaraaplicaçãorequirejs(["main"]);
})();
But now autosize.js
shows the following error: TypeError: $ is not a function
, the code is original without any changes and I'm using version 1.18.18 on link