Why google closure builder ignores goog.addDependency?

222 views Asked by At

I have an application using google closure. When I create a component I add in my deps.js file this code:

goog.addDependency('path/to/my/component.js', ['My.Component'], [
  'goog.ui.Component',
  'another.one.dependency'
]);

Then I create component.js file:

goog.provide('My.Component');

My.Component = function() {
  ...
}

It works. But when I create a build using closure builder closure builder ignores goog.addDependency code and it doesn't include dependencies in the build. So, if I want to include dependecies in the build I should add goog.require() in component.js:

goog.provide('My.Component');

goog.require('goog.ui.Component');
goog.require('another.one.dependency');

My.Component = function() {
  ...
}

This is inconvenient for me because I already have more than hundred files that haven't got goog.require() statements in their code.

1

There are 1 answers

0
TWL On BEST ANSWER

Since Closurebuilder calculate dependencies itself you need to use requires.

You dont need to require everything needed in every file though, for example if you require goog.ui.Component in your main file, all the components can access it.

For development I would suggest using Plovr. It also calculates dependencies on the fly, so you dont need to worry about generating a deps file when developing.