I have a parent project that contains a child module. The module has its own bower.json
which specifies the module dependencies and .bowerrc
which specifies which folder these should be downloaded into. These dependencies are linked in the module HTML.
The parent project uses package.json
to manage Node dependencies.
To prevent users having to run both npm install
(for the parent dependencies) and cd module
, bower install
, cd ../
(for the module dependencies), I have added a postinstall
script to package.json
:
"scripts": {
"postinstall" : "./node_modules/.bin/bower install ./module/ --config.directory=\"./module/public/bower_components\""
}
Note that the only way that I could get Bower to install the module's dependencies into /module/public/bower_components
was to explicitly state the directory
in the postinstall
script.
However ./module/.bowerrc
already contains this information, so ideally I'd like to 'make' the bower install
aware of this. This would also make package.json
easier to maintain and module
more portable.
I've also tried transferring the Bower dependency and postinstall
script into my module's package.json
, using the postinstall
hook in the parent's package.json
to run npm install
in the module directory. But this approach ends in module. dependencies being downloaded into the parent's node_modules
folder.
Is there a better way to solve this?
Bower config uses the following order of precedence to resolve configurations for the build.
From bower docs at http://bower.io/docs/config/
In your case you can put a .bowerrc file in the same folder as package.json but configure all the properties with prefix module/public to get your setup working.
I do like your idea of managing all the dependencies from one place in package.json.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With