javascriptrequirejsmarionettegrunt-contrib-requirejs

Alternative to require our app module each time to debug in console


When I want to debug my requirejs app, I need to reference my application everytime with something like:

var App = require('app');

as stated here:

http://requirejs.org/docs/api.html#modulenotes

From that moment I can access everything via console because the App variable points to my application instance.. However, it is very annoying to have to do it after every page refresh. Is there any alternative that would help improve the development workflow?


Solution

  • You could deliberately export a reference to your application into the global space. This is actually what I do. I select a name that has very little likelihood of clashing. In your app module you could do this after your App object is created: window._myproject_app = App. This is then accessible as the global _myproject_app. You can start writing the first characters and use autocomplete rather than type the whole thing when you want to access it.

    If you want the export to occur only in testing you can use RequireJS' config facility to pass configuration that tells the module responsible to export the instance whether it should export it or not.