{"issue":{"title":"When building modules are added twice or some times thrice","created_at":"2011-12-13T11:08:05Z","milestone":null,"user":{"id":129355,"login":"mailaneel","url":"https://api.github.com/users/mailaneel","gravatar_id":"348c7cfb754cc329afa2b91b3c6dc5d7","avatar_url":"https://secure.gravatar.com/avatar/348c7cfb754cc329afa2b91b3c6dc5d7?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"labels":[],"updated_at":"2011-12-23T05:34:54Z","state":"closed","id":2535358,"closed_at":"2011-12-23T05:30:13Z","html_url":"https://github.com/jrburke/r.js/issues/56","pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"body":"# Issue 1\r\n\r\nIf 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\r\n\r\n 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\r\n\r\n# Issue 2\r\n\r\nIf 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\r\n\r\n# Gist Link\r\n[Gist](https://gist.github.com/1471705)\r\n\r\n# Below is my build file\r\n\r\n```javascript\r\n\r\n    ({\r\n    appDir: \"../\",\r\n    baseUrl: \"web/\",\r\n    dir: \"../../project-build\",\r\n    //Comment out the optimize line if you want\r\n    //the code minified by UglifyJS\r\n    optimize: \"none\",\r\n\r\n    paths: {\r\n        \"order\": \"../common/js/vendor/requirejs/plugins/order\",\r\n        \"text\": \"../common/js/vendor/requirejs/plugins/text\",\r\n        \"i18n\": \"../common/js/vendor/requirejs/plugins/i18n\",\r\n        \"wsl\":\"../common/js/vendor/wsl/base\",\r\n        \"goog\":\"../common/js/vendor/goog\",\r\n        \"bootstrap\":\"../common/js/vendor/bootstrap\",\r\n        \"iscroll\":\"../common/js/vendor/iscroll\",\r\n        \"jquery\":\"../common/js/vendor/jquery\",\r\n        \"layout\":\"../common/js/vendor/layout\",\r\n        \"mustache\":\"../common/js/vendor/mustache\",\r\n        \"underscore\":\"../common/js/vendor/underscore/underscore\",\r\n        \"spine\":\"../common/js/vendor/spine\",\r\n        \"models\":\"../core/models\",\r\n        \"web\":\"modules\", // this is the base path for web\r\n\r\n        //All modules should be configured here\r\n        \"web.config\":\"modules/config/config\",\r\n        \"web.app\":\"modules/app/app\",\r\n        \"web.actionBar\":\"modules/actionBar/actionBar\",\r\n        \"web.sideBar\":\"modules/sideBar/sideBar\"\r\n    },\r\n\r\n    modules: [\r\n    //for some reasons if you add more than one module here during the build process modules are added twice and sometimes thrice\r\n    // so if you want to make a build for production add dependencies in production.js file\r\n    {\r\n        name: \"production\"\r\n    },\r\n   {\r\n        name: \"web.sideBar\"\r\n    }\r\n    ]\r\n})\r\n```\r\n# Main File\r\n\r\n``` javascript\r\nrequire.config({\r\n    //what ever paths you mention here should be copied to build file\r\n    paths: {\r\n        \"order\": \"../common/js/vendor/requirejs/plugins/order\",\r\n        \"text\": \"../common/js/vendor/requirejs/plugins/text\",\r\n        \"i18n\": \"../common/js/vendor/requirejs/plugins/i18n\",\r\n        \"wsl\":\"../common/js/vendor/wsl/base\",\r\n        \"goog\":\"../common/js/vendor/goog\",\r\n        \"bootstrap\":\"../common/js/vendor/bootstrap\",\r\n        \"iscroll\":\"../common/js/vendor/iscroll\",\r\n        \"jquery\":\"../common/js/vendor/jquery\",\r\n        \"layout\":\"../common/js/vendor/layout\",\r\n        \"mustache\":\"../common/js/vendor/mustache\",\r\n        \"underscore\":\"../common/js/vendor/underscore/underscore\",\r\n        \"spine\":\"../common/js/vendor/spine\",\r\n        \"models\":\"../core/models\",\r\n        \"web\":\"modules\",\r\n        \r\n        //All modules should be configured here\r\n        \"web.config\":\"modules/config/config\",\r\n        \"web.app\":\"modules/app/app\",\r\n        \"web.actionBar\":\"modules/actionBar/actionBar\",\r\n        \"web.sideBar\":\"modules/sideBar/sideBar\"\r\n    },\r\n    waitSeconds: 15,\r\n    locale: \"fr-fr\"\r\n});\r\n\r\nrequire(\r\n    [\r\n    'wsl',\r\n    'order!spine/spine',\r\n    'order!spine/route',\r\n    'order!spine/manager',\r\n    'layout/layout',\r\n    'iscroll/iscroll'\r\n    ],function(){\r\n         wsl.provide('web');\r\n         wsl.provide('web.Config');\r\n        //Start Application\r\n        require(['order!web.config','order!web.app'], function(config,App){ \r\n            web.Config = config;\r\n            $(document).ready(function(){\r\n                var app = new App();\r\n                app.start();\r\n            });\r\n    \r\n        }); \r\n    });\r\n \r\n\r\n\r\n```\r\n# Production File\r\n\r\n```javascript\r\n\r\nrequire(['main'],function(){\r\n    //from here main config will be loaded so the urls will be changed according to the config\r\n    \r\n    require(['web.sideBar']);\r\n    require(['web.actionBar']);\r\n});\r\n\r\n\r\n\r\n```\r\n\r\n# web.sideBar\r\n\r\n``` javascript\r\n\r\ndefine('web.sideBar',\r\n    [\r\n    'text!web/sideBar/html/sideBar.html!strip',\r\n    'text!web/sideBar/css/sideBar.css',\r\n    'i18n!web/sideBar/nls/i18n' \r\n    ],\r\n    function(html,css,language){\r\n        \r\n        var SideBar = Spine.Controller.sub();\r\n        \r\n        SideBar.extend({\r\n            module: {\r\n                name: 'web.sideBar',\r\n                css: css,\r\n                lang: language\r\n            }\r\n        });\r\n            \r\n        SideBar.include({\r\n            init: function(){\r\n                this.render();\r\n            },\r\n            render: function(){\r\n                console.log(\"I am render from Side Bar\");\r\n                var self = this;\r\n                    var options = {\r\n                        element: self.el,\r\n                        tpl:html, \r\n                        module:SideBar.module\r\n                    };\r\n                    wsl.module.render(options);\r\n            },\r\n            bindEvents: function(){\r\n                \r\n            }\r\n        });       \r\n        return SideBar;\r\n    });\r\n\r\n\r\n\r\n```\r\n\r\n# web.actionBar\r\n\r\n``` javascript\r\ndefine('web.actionBar',\r\n    [\r\n    'text!web/actionBar/html/actionBar.html!strip',\r\n    'text!web/actionBar/css/actionBar.css',\r\n    'i18n!web/actionBar/nls/i18n'\r\n    ],\r\n    function(html,css,language){\r\n        \r\n        var ActionBar = Spine.Controller.sub();\r\n        \r\n        ActionBar.extend({\r\n            module: {\r\n                name: 'web.actionBar',\r\n                css: css,\r\n                lang: language\r\n            }\r\n        });\r\n            \r\n        ActionBar.include({\r\n            init: function(){\r\n                this.render();\r\n            },\r\n            render: function(){\r\n                console.log(\"I am render from Action Bar\");\r\n                var self = this;\r\n                    var options = {\r\n                        element: self.el,\r\n                        tpl:html, \r\n                        module:ActionBar.module\r\n                    };\r\n                    wsl.module.render(options);\r\n            },\r\n            bindEvents: function(){\r\n                \r\n            }\r\n        });       \r\n        return ActionBar;\r\n    });\r\n\r\n\r\n\r\n\r\n```\r\n\r\n\r\n\r\n","number":56,"url":"https://api.github.com/repos/jrburke/r.js/issues/56","comments":6,"assignee":null},"comment":{"created_at":"2011-12-23T05:34:54Z","user":{"id":73359,"login":"jrburke","url":"https://api.github.com/users/jrburke","gravatar_id":"00ac28bdce61e7db41be57fb3b7f3525","avatar_url":"https://secure.gravatar.com/avatar/00ac28bdce61e7db41be57fb3b7f3525?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"updated_at":"2011-12-23T05:34:54Z","id":3258246,"body":"I looked more into this, and the problem is this: when the 'web.actionBar' module is optimized, it is written to disk with all of its dependencies inside it.This is done before the 'production' output is written to disk. The 'production' depends on 'web.actionBar' so when 'production' comes second in the list, it picks up the contents of the **optimized** web.actionBar, which includes the plugins.\r\n\r\nSo I did a fix to not write out the build layers to their final names until all the build layers have been written to disk at temporary names, then move them to their final position.\r\n\r\nYou can try [r-edge.js](https://raw.github.com/jrburke/r.js/master/dist/r-edge.js) to verify the fix. This will go into the 1.0.3 release.\r\n\r\nThank you very much for the test case.\r\n","url":"https://api.github.com/repos/jrburke/r.js/issues/comments/3258246"},"action":"created"}