I am using requirejs in my project and each module has a js file using require calls to make use of libraries/components. Following is sample code :-
require(["modernizr",
"jquery",
"bootstrap",
"handlebars",
"bootstrap-table",
], function(modernizr, $, bootstrap, Handlebars, bootstrapTable) {
$(document).on('click', '#searchBtn', function(e){
search();
});
$('#table').bootstrapTable({
classes: 'table table-no-bordered',
striped: true,
iconsPrefix: 'fa',
responsive: true,
responsiveBreakPoint: 768,
responsiveClass: "bootstrap-table-cardview",
undefinedText: "",
showFooter: true,
columns: columns(),
data: data(),
});
}
I want to minimize the number of js calls in the browser while page load.
(I am aware of r.js but would like to avoid it as it requires me change my project folder structure)
So I am thinking of concatenating and minifying all library/component js files like jquery, bootstrap etc. using grunt and then require them in module specific files.
If I do so, I wanted to know how I can include the same using require and be able to use jquery($) and bootstrapTable the way I am using now?
I tried the following but it does not seem to be working :-
require(["mainjs"], function(mainjs) {
mainjs(document).on('click', '#searchBtn', function(e){
search();
});
mainjs('#table').mainjs({
classes: 'table table-no-bordered',
striped: true,
iconsPrefix: 'fa',
responsive: true,
responsiveBreakPoint: 768,
responsiveClass: "bootstrap-table-cardview",
undefinedText: "",
showFooter: true,
columns: columns(),
data: data(),
});
}
Following is my project structure :-
my-proj
build
src
app
components
selectpicker
selectpicker.hbs
selectpicker.js
selectpicker.less
calendar
calendar.hbs
calendar.js
calendar.less
...
...
...
page
homepage
homepage.html
homepage.js
transacations
transactions.html
transactions.js
...
...
...
assets
images
js
jquery.js
modernizr.js
handlebar.js
require.js
bootstrap.js
moment.js
...
...
...
less
Gruntfile.js
package.json