I am using grunt-browserify and is facing two problems in particular. This task has been successfully started and works with the following configuration parameters. The jsFilesToConcat variable represents all the javascript files for the Backbone.js + Marionette.js application, the main application fix, front-end front-end utilities (e.g. Bootstrap plugins), and all the JS associated with the project. Is this the wrong approach? The idea was to download the entire application for 250 thousand JS (and all its dependencies) at a time.
I want to offer a disclaimer that this is a new territory for me, so I think that my alleged use case is available with options already available with the plugin, but two errors confuse me:
1) Backbone not defined - this means that the script is actually loading, however, when I check the call stack in Chrome Dev Tools, it shows only the anonymous self-starting function. Therefore, I donβt understand how to pass the Backbone object to Marionette so that it expands at boot time.
2) require is not defined - an error in the line where I declare var SampleApp = require('SampleApp') . Do I need to do something special in my grunt or node.js server.js config configuration to open the require function?
3) Is javascript executing asynchronously within itself, is this part of the browser the intended behavior that I am processing incorrectly? I think that since I am wrapping many JS utilities in the global shell to protect the namespace, the reason is that some functions are not available, but I do not understand why this would affect require .
// uses grunt-browserify task browserify: { developmentJs: { options: { debug: true, alias: ["./js/app.dev.js:SampleApp"], }, src: [ '<%= pkg.jsFilesToConcat %>' ], dest: 'public-dev/js/app.dev.js' } }
and then in the index.html my single page Marionette app I have.
(function ($) { $(document).ready( function() { var sampleApp = require('SampleApp'); console.log( SampleApp ); }); })(jQuery);