Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying the location of .bowerrc when calling bower install

I have a parent project that contains a child module. The module has its own bower.json which specifies the module dependencies and .bowerrcwhich 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?

like image 314
Dan Avatar asked Mar 04 '15 21:03

Dan


1 Answers

Bower config uses the following order of precedence to resolve configurations for the build.

From bower docs at http://bower.io/docs/config/

  • CLI arguments via --config
  • Environment variables
  • Local .bowerrc located in the current working directory
  • All .bowerrc files upwards the directory tree
  • .bowerrc file located in user’s home folder (~)
  • .bowerrc file located in the global folder (/)

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.

like image 53
Prabhu Velayutham Avatar answered Oct 13 '22 00:10

Prabhu Velayutham