Useful .bowerrc settings
I wanted to note a couple of configuration options in the .bowerrc configuration file from the bower package management system.
directory
I’ve been using this to embed UI package into projects that have the UI portion as a subdirectory of the main project while keeping the bower.json file at the top level of the project.
For instance if a project layout is as follows:
.
├── web
│ ├── js
│ ├── img
│ └── index.html
├── code
├── .editorconfig
├── .gitignore
├── Makefile
└── bower.json
If you run the bower install
command in the root of the project it produces
the following:
.
├── web
│ ├── js
│ ├── img
│ └── index.html
├── bower_components
│ ├── bower_package_1
│ ├── bower_package_2
│ └── ...
├── code
├── .editorconfig
├── .gitignore
├── Makefile
└── bower.json
This creates the bower_components directory in the root of the project.
I wanted to create the bower components in the web/vendor directory. Create the following:
The first one is hte directory
option.
{
"directory": "web/vendor"
}
and now the bower install
command will produce the following:
.
├── web
│ ├── bower_components
│ │ ├── bower_package_1
│ │ ├── bower_package_2
│ │ └── ...
│ ├── js
│ ├── img
│ └── index.html
├── code
├── .editorconfig
├── .gitignore
├── Makefile
└── bower.json
interactive
For automation purpose, using tools like Makefiles, Ansible, and Puppet, I’ve found if extremely useful to run bower in non-interactive mode.
This will disable a lot of prompts that happend when you’re runing the tools from manually and fail fast. This save a lot of debugging time when running bower inside your automation tools.
To configure the non-interactive do the following:
{
"analytics": false
}
analytics
While attempting to automate aspects of projects that uses bower, using tools like Makefiles, Ansible, and Puppet, I kept hitting an issue where the auotmation would hang with a message like:
May bower anonymously report usage statistics to improve the tool over time? (Y/n)
After searching for how others handled this issue, I ran accross articles like
this one:
Stop bower from asking for statistics when installing.
It suggests setting the analytics
option to false
.
{
"analytics": false
}
allow_root
This seems to be random, depending on the OS/version, but at times if running bower inside a docker container and the build fails with an error like the following (or similar):
bower ESUDO Cannot be run with sudo
Typically the user that runs commands inside a docker container is the root
user. bower doesn’t allow this behaviour by default.
This issue can be worked around by following the steps described in articles like this one: Can’t get bower working - bower ESUDO Cannot be run with sudo.
It discribes setting the allow_root
property as follows:
{
"allow_root": true
}