jrburke/r.js — Issue #56: When building modules are added twice or some times thrice
Author: mailaneel
Created: 2011-12-13 11:08:05+00:00
State: open

# Issue 1

If i add more than one module name to build, in the production.js after the build is done i am getting file duplicates, text,i18n,order plugins are added more than once. text files and language file are also added more than once, I am also adding the build production.js file for reference, please scroll bottom to see the multiple additions

if i change the order in build file i am getting duplicates, just search for define('i18n' in the gist link, the production.js will have 2 "i18n" modules, production1.js will have 1 "i18n" module, the only difference is the module order in build file

# Issue 2

If i add require inside define that is not combined during the build process, try loading html file in some function and build the file html file is not added to the build it is loaded using a separate request

# Gist Link
[Gist](https://gist.github.com/1471705)

# Below is my build file

```javascript

({
appDir: "../",
baseUrl: "web/",
dir: "../../project-build",
//Comment out the optimize line if you want
//the code minified by UglifyJS
optimize: "none",

paths: {
"order": "../common/js/vendor/requirejs/plugins/order",
"text": "../common/js/vendor/requirejs/plugins/text",
"i18n": "../common/js/vendor/requirejs/plugins/i18n",
"wsl":"../common/js/vendor/wsl/base",
"goog":"../common/js/vendor/goog",
"bootstrap":"../common/js/vendor/bootstrap",
"iscroll":"../common/js/vendor/iscroll",
"jquery":"../common/js/vendor/jquery",
"layout":"../common/js/vendor/layout",
"mustache":"../common/js/vendor/mustache",
"underscore":"../common/js/vendor/underscore/underscore",
"spine":"../common/js/vendor/spine",
"models":"../core/models",
"web":"modules", // this is the base path for web

//All modules should be configured here
"web.config":"modules/config/config",
"web.app":"modules/app/app",
"web.actionBar":"modules/actionBar/actionBar",
"web.sideBar":"modules/sideBar/sideBar"
},

modules: [
//for some reasons if you add more than one module here during the build process modules are added twice and sometimes thrice
// so if you want to make a build for production add dependencies in production.js file
{
name: "production"
},
{
name: "web.sideBar"
}
]
})
```
# Main File

``` javascript
require.config({
//what ever paths you mention here should be copied to build file
paths: {
"order": "../common/js/vendor/requirejs/plugins/order",
"text": "../common/js/vendor/requirejs/plugins/text",
"i18n": "../common/js/vendor/requirejs/plugins/i18n",
"wsl":"../common/js/vendor/wsl/base",
"goog":"../common/js/vendor/goog",
"bootstrap":"../common/js/vendor/bootstrap",
"iscroll":"../common/js/vendor/iscroll",
"jquery":"../common/js/vendor/jquery",
"layout":"../common/js/vendor/layout",
"mustache":"../common/js/vendor/mustache",
"underscore":"../common/js/vendor/underscore/underscore",
"spine":"../common/js/vendor/spine",
"models":"../core/models",
"web":"modules",

//All modules should be configured here
"web.config":"modules/config/config",
"web.app":"modules/app/app",
"web.actionBar":"modules/actionBar/actionBar",
"web.sideBar":"modules/sideBar/sideBar"
},
waitSeconds: 15,
locale: "fr-fr"
});

require(
[
'wsl',
'order!spine/spine',
'order!spine/route',
'order!spine/manager',
'layout/layout',
'iscroll/iscroll'
],function(){
wsl.provide('web');
wsl.provide('web.Config');
//Start Application
require(['order!web.config','order!web.app'], function(config,App){
web.Config = config;
$(document).ready(function(){
var app = new App();
app.start();
});

});
});

```
# Production File

```javascript

require(['main'],function(){
//from here main config will be loaded so the urls will be changed according to the config

require(['web.sideBar']);
require(['web.actionBar']);
});

```

# web.sideBar

``` javascript

define('web.sideBar',
[
'text!web/sideBar/html/sideBar.html!strip',
'text!web/sideBar/css/sideBar.css',
'i18n!web/sideBar/nls/i18n'
],
function(html,css,language){

var SideBar = Spine.Controller.sub();

SideBar.extend({
module: {
name: 'web.sideBar',
css: css,
lang: language
}
});

SideBar.include({
init: function(){
this.render();
},
render: function(){
console.log("I am render from Side Bar");
var self = this;
var options = {
element: self.el,
tpl:html,
module:SideBar.module
};
wsl.module.render(options);
},
bindEvents: function(){

}
});
return SideBar;
});

```

# web.actionBar

``` javascript
define('web.actionBar',
[
'text!web/actionBar/html/actionBar.html!strip',
'text!web/actionBar/css/actionBar.css',
'i18n!web/actionBar/nls/i18n'
],
function(html,css,language){

var ActionBar = Spine.Controller.sub();

ActionBar.extend({
module: {
name: 'web.actionBar',
css: css,
lang: language
}
});

ActionBar.include({
init: function(){
this.render();
},
render: function(){
console.log("I am render from Action Bar");
var self = this;
var options = {
element: self.el,
tpl:html,
module:ActionBar.module
};
wsl.module.render(options);
},
bindEvents: function(){

}
});
return ActionBar;
});

```