A Bower package may specify in its bower.json a dependency on other packages. Bower uses this to install the dependent packages automatically. The jquery-ui package for instance depends on the jquery package, so when you install jquery-ui, the jquery package is automatically installed as well.
BowerStatic also uses this information. If you include the endpoint of a package (by not specifying the file), the endpoints of the dependencies are also included automatically.
This is different from dependencies between individual static resources. Bower has no information about these, and in fact there is no universal system on the client to determine these.
In order to use dependencies you need to specify extra information for resources. This is done using the resource method on the directory object:
components = bower.components('components', '/path/to/bower_components') components.resource( 'jquery-ui/ui/minified/jquery-ui.min.js', dependencies=['jquery/dist/jquery.min.js'])
Here we express that the jquery-ui.min.js resource depends on the jquery.min.js resource.
When you now depend on jquery-ui/ui/minified/jquery-ui.min.js using the same components object:
include = components.includer(environ) include('jquery-ui/ui/minified/jquery-ui.min.js')
an inclusion to the minified jQuery is also generated:
The .resource method in fact creates a resource object that you can assign to a variable:
jquery_min = components.resource( 'jquery/dist/jquery.min.js')
You can use this resource object in an include:
This has the same effect as referring to the resource directory using a string.
You can also refer to this resource in another resource definition:
jquery_ui_min = components.resource( 'jquery-ui/ui/minified/jquery-ui.min.js', dependencies=[jquery_min])
Dealing with explicit resource objects can be handy as it saves typing, and Python gives you an error if you refer to a resource object that does not exist, so you can catch typos early.
It is sometimes useful to be able to generate the URL for a component itself, for instance when client-side code needs to construct URLs to things inside it, such as templates. To support this case, you can get the URL of a component by writing this:
This will generate the appropriate versioned URL to that component.