I am having problems with minification of my application. My goal is to have as few as possible Javascript files. I am getting partial results, I am able to concatenate all of the files that are located in the lib/ folder. They are all bundled in main.js file and it works fine.
However, the rest of the application files are not bundled in one file, they are only minified and uglified.
I am using node to start the proccess using this command:
node r.js -o build.js
My application folder structure:
- CSS
- img
- js
- Collections
- Models
- lib
- routers
- Views
- Controllers
- Templates(handlebar files)
- app.js
- main.js
- config.js
- r.js
- build.js
My build.js file:
({
appDir: './',
baseUrl: './js',
dir: './dist',
modules: [
{
name: 'main'
}
],
fileExclusionRegExp: /^(r|build)\.js$/,
optimizeCss: 'standard',
removeCombined: true,
paths: {
underscore : 'lib/underscore',
backbone : 'lib/backbone',
babysitter : 'lib/backbone.babysitter',
wreqr : 'lib/backbone.wreqr',
marionette : 'lib/backbone.marionette',
handlebars : 'lib/handlebars',
jquery : 'lib/jquery',
jqueryui : 'lib/jqueryui',
text : 'lib/text',
templates : '../templates'
},
shim: {
underscore: {
exports: '_'
},
backbone: {
exports: 'Backbone',
deps: ['jquery', 'underscore']
},
jqueryui: {
exports: '$',
deps: ['jquery']
},
babysitter: {
exports: 'Backbone.Babysitter',
deps: ['backbone']
},
wreqr: {
exports: 'Backbone.Wreqr',
deps: ['backbone']
},
marionette: {
exports: 'Backbone.Marionette',
deps: [
'backbone',
'babysitter',
'wreqr',
'lib/json2'
]
},
handlebars: {
exports: 'Handlebars'
},
'lib/marionette.handlebars': {
exports: 'Marionette.Handlebars',
deps: ['handlebars', 'marionette']
}
'lib/foundation.reveal': {
exports: '$',
deps: ['lib/foundation']
},
'lib/foundation.dropdown': {
exports: '$',
deps: ['lib/foundation']
}
},
deps: ['jquery', 'underscore']
})
This is my main.js file:
require.config({
baseURL: '.',
urlArgs: "ver=2", //Control Client Cache. Change this value for every new release.
paths: {
underscore : 'lib/underscore',
backbone : 'lib/backbone',
babysitter : 'lib/backbone.babysitter',
wreqr : 'lib/backbone.wreqr',
marionette : 'lib/backbone.marionette',
handlebars : 'lib/handlebars',
jquery : 'lib/jquery',
jqueryui : 'lib/jqueryui',
text : 'lib/text',
templates : '../templates'
},
waitSeconds: 60,
shim: {
underscore: {
exports: '_'
},
backbone: {
exports: 'Backbone',
deps: ['jquery', 'underscore']
},
jqueryui: {
exports: '$',
deps: ['jquery']
},
babysitter: {
exports: 'Backbone.Babysitter',
deps: ['backbone']
},
wreqr: {
exports: 'Backbone.Wreqr',
deps: ['backbone']
},
marionette: {
exports: 'Backbone.Marionette',
deps: [
'backbone',
'babysitter',
'wreqr',
'lib/json2'
]
},
handlebars: {
exports: 'Handlebars'
},
'lib/marionette.handlebars': {
exports: 'Marionette.Handlebars',
deps: ['handlebars', 'marionette']
},
'lib/foundation': {
exports: '$',
deps: ['jquery']
},
'lib/foundation.orbit': {
exports: '$',
deps: ['lib/foundation']
},
'lib/foundation.reveal': {
exports: '$',
deps: ['lib/foundation']
},
'lib/foundation.dropdown': {
exports: '$',
deps: ['lib/foundation']
}
},
deps: ['jquery', 'underscore']
});
require(['app', 'backbone', 'config'], function(App, Backbone, Config) {
App.start(Config);
});