Is there any way I can use Google Closure goog.require
to manage JS dependencies, without having to register each namespace explicitly in a dependencies.js file?
I like the idea of the compiler for production, but for development, I'd like some kind of convention-over-configuration translation of namespace to JS folder/path such that something like goog.require('myapp.module')
automatically imports myapp/module.js
in development mode (if not already imported), while in production it all gets compiled into a single file.
I seem to remember old versions of dojo.require
worked this way. Any idea if Google Closure can do the same thing?
The short answer is no. In uncompiled JavaScript code,
goog.require()
relies on a dependency graph generated by calls togoog.addDependency(relativePath, provides, requires).
From the DepsWriter documentation:
That being said, you could use a tool such as plovr, which provides a "RAW" mode to concatenate your JavaScript sources without compilation. This avoids the need to generate a deps file, but it also means that when debugging code in the browser, it is more challenging to determine the original file containing the code.