Skip to content

Instantly share code, notes, and snippets.

@roachhd
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roachhd/66b10d697e46fb58051e to your computer and use it in GitHub Desktop.
Save roachhd/66b10d697e46fb58051e to your computer and use it in GitHub Desktop.
All About Bower: bower.json specification; ReadME.md, config

Bower

Build Status Coverage Status

A package manager for the web

Bower offers a generic, unopinionated solution to the problem of front-end package management, while exposing the package dependency model via an API that can be consumed by a more opinionated build stack. There are no system wide dependencies, no dependencies are shared between different apps, and the dependency tree is flat.

Bower runs over Git, and is package-agnostic. A packaged component can be made up of any type of asset, and use any type of transport (e.g., AMD, CommonJS, etc.).

View complete docs on bower.io

View all packages available through Bower's registry.

Install

$ npm install -g bower

Bower depends on Node.js and npm. Also make sure that git is installed as some bower packages require it to be fetched and installed.

Usage

See complete command line reference at bower.io/docs/api/

Installing packages and dependencies

# install dependencies listed in bower.json
$ bower install

# install a package and add it to bower.json
$ bower install <package> --save

# install specific version of a package and add it to bower.json
$ bower install <package>#<version> --save

Using packages

We discourage using bower components statically for performance and security reasons (if component has an upload.php file that is not ignored, that can be easily exploited to do malicious stuff).

The best approach is to process components installed by bower with build tool (like Grunt or gulp), and serve them concatenated or using module loader (like RequireJS).

Uninstalling packages

To uninstall a locally installed package:

$ bower uninstall <package-name>

prezto and oh-my-zsh users

On prezto or oh-my-zsh, do not forget to alias bower='noglob bower' or bower install jquery\#1.9.1

Running commands with sudo

Bower is a user command, there is no need to execute it with superuser permissions. However, if you still want to run commands with sudo, use --allow-root option.

Windows users

To use Bower on Windows, you must install msysgit correctly. Be sure to check the option shown below:

msysgit

Note that if you use TortoiseGit and if Bower keeps asking for your SSH password, you should add the following environment variable: GIT_SSH - C:\Program Files\TortoiseGit\bin\TortoisePlink.exe. Adjust the TortoisePlink path if needed.

Configuration

Bower can be configured using JSON in a .bowerrc file. Read over available options at bower.io/docs/config.

Completion (experimental)

NOTE: Completion is still not implemented for the 1.0.0 release

Bower now has an experimental completion command that is based on, and works similarly to the npm completion. It is not available for Windows users.

This command will output a Bash / ZSH script to put into your ~/.bashrc, ~/.bash_profile, or ~/.zshrc file.

$ bower completion >> ~/.bash_profile

Support

Contributing

We welcome contributions of all kinds from anyone. Please take a moment to review the guidelines for contributing.

Bower Team

Bower is made by lots of people across the globe, contributions large and small. Our thanks to everyone who has played a part.

Core team

Bower Alumni

License

Copyright (c) 2014 Twitter and other contributors

Licensed under the MIT License

bower.json specification

name

Required
Type: String

The name of the package as stored in the registry.

  • Must be unique.
  • Should be slug style for simplicity, consistency and compatibility. Example: unicorn-cake
  • Lowercase, a-z, can contain digits, 0-9, can contain dash or dot but not start/end with them.
  • Consecutive dashes or dots not allowed.
  • 50 characters or less.

description

Recommended
Type: String

Any character. Max 140.

Help users identify and search for your package with a brief description. Describe what your package does, rather than what it's made of. Will be displayed in search/lookup results on the CLI and the website that can be used to search for packages.

version

Ignored by Bower as git tags are used instead.

Intended to be used in the future when Bower gets a real registry where you can publish actual packages, but for now just leave it out.

Type: `String`

The package's semantic version number.

  • Must be a semantic version parseable by node-semver.
  • If publishing a folder, the version must be higher than the version stored in the registry, when republishing.
  • Version should only be required if you are not using git tags.

main

Recommended
Type: String or Array of String

The primary acting files necessary to use your package. While Bower does not directly use these files, they are listed with the commands bower list --json and bower list --paths, so they can be used by build tools.

  • Preprocessor files like CoffeeScript should be compiled.
  • Do not include minified files.
  • Filenames should not be versioned (Bad: package.1.1.0.js; Good: package.js).

license

Recommended
Type: String or Array of String

SPDX license identifier or path/url to a license.

ignore

Recommended
Type: Array of String

A list of files for Bower to ignore when installing your package.

Note: README (all variants of case, .md, .text) and bower.json will never be ignored.

The ignore rules follow the same rules specified in the gitignore pattern spec.

keywords

Recommended
Type: Array of String

Same format requirements as name.

Used for search by keyword. Helps make your package easier to discover without people needing to know its name. Recommended.

authors

Type: Array of (String or Object)

A list of people that authored the contents of the package.

Either:

"authors": [
  "John Doe", "John Doe <john@doe.com>",
  "John Doe <john@doe.com> (http://johndoe.com)"
]

or:

"authors": [
  { "name": "John Doe" },
  { "name": "John Doe", "email": "john@doe.com" },
  { "name": "John Doe", "email": "john@doe.com", "homepage": "http://johndoe.com" }
]

homepage

Type: String

URL to learn more about the package. Falls back to GitHub project if not specified and it’s a GitHub endpoint.

repository

Type: Object

The repository in which the source code can be found.

"repository": {
  "type": "git",
  "url": "git://github.com/foo/bar.git"
}

dependencies

Type: Object

Dependencies are specified with a simple hash of package name to a semver compatible identifier or URL.

  • Key must be a valid name.
  • Value must be a valid version, a Git URL, or a URL (inc. tarball and zipball).
  • Value can be an owner/package shorthand, i.e. owner/package. By default, the shorthand resolves to GitHub -> https://github.com/owner/package. This may be changed in .bowerrc shorthand_resolver.
  • Local paths may be used as values for local development, but they will be disallowed when registering.

devDependencies

Type: Object

Same rules as dependencies.

Dependencies that are only needed for development of the package, e.g., test framework or building documentation.

resolutions

Type: Object

Dependency versions to automatically resolve with if conflicts occur between packages.

Example:

"resolutions": {
  "angular": "1.3.0-beta.16"
}

private

Type: Boolean

If you set it to true it will refuse to publish it. This is a way to prevent accidental publication of private repositories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment