I've been working with RequireJS for a bit lately but I am brand new to the optimizer and I am trying to add it into my build steps but I am running into an issue. After it runs and merges my JS files into one, the body of my "main" no longer executes (worked fine prior to optimizing). All of the dependency JS loads correctly but the actual code inside of my main define() does not (even though I can see it in the final output file. Here is what I mean:
Assuming simplified version of my main.js:
console.log("This statement outputs to console");
define(["jquery", "modernizr", "jquery.joyride"], function($) {
console.log("This statement does not");
}
As I mentioned I will see jquery, modernizer, joyride and both console.log() statements in inline in the output file so I believe it is getting generated correctly. My guess is that it has to do with my require config:
This is simplified version of my app.js:
requirejs.config({
"baseUrl": "/assets/js",
"paths": {
"jquery": "jquery"
},
"shim": {
"jquery.joyride": ["jquery"]
}
});
requirejs(["app/main"]);
My assumption is that the second requirejs() call is not getting executed. Is that possible? What would cause that to happen and what is the proper fix?
Essentially my optimized version of main.js looks something like the following:
(function(e,t){ ..jquery code.. };
define("jquery.joyride", function(){});
(function(a){ ...code here... });
console.log("This statement outputs to console");
define('main',["jquery", "modernizr", "jquery.joyride"], function($) {
console.log("This statement does not");
};
Here is by build config:
({
appDir: '../../',
baseUrl: "assets/js",
mainConfigFile: '../../assets/js/app.js',
dir: '../../../BUILD/',
optimizeCss: 'default',
modules: [
{
name: "main"
}
],
removeCombined: true,
preserveLicenseComments: false,
optimize: 'none' // I Disabled this to help me try and debug
})
Also it it helps, this is the line I'm using to include my JS (same exact line boht before and after I optimize the file):
<script data-main="/assets/js/app" src="/assets/js/require.js"></script>