4
Óla gente,
I am in doubt of properly configuring the RequireJS
, as I also have doubts about the organization of Trees to configure the baseUrl
and so I’m going to demonstrate how I’m configuring:
.
├── 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 tree structure of the project and the index.html
put these settings:
<script type="text/JavaScript" data-main="js/boot" src="vendor/require.js"></script>
So far Requirejs loads the problem is to call the jQuery
, before I will show the configuration code 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 spin it works up to a certain point which is the jQuery
that does not carry, realize that I use a technique that is the noConflict
and in it comes the problem, he says he does not recognize the function TypeError: jQuery is undefined
and when I see in the requests the module defined in paths
does not carry:
I managed to solve the problem of noConflict.js
using this code in the file boot.js
(File you have to Requirejs settings):
;(function( undefined ) {
'use strict';
requirejs.config({
baseUrl: 'js/lib',
paths: {
// Módulo jQuery
'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'
}
}
});
// Chamando módulo principal para iniciar a aplicação
requirejs(["main"]);
})();
But now the autosize.js
shows the following error: TypeError: $ is not a function
, where the code is original without changes and I am using version 1.18.18 on the website http://www.jacklmoore.com/autosize
Very good your tutorial, helped me a lot!
– Gleyson Silva