使用bower 管理 javascript, css...

访问量: 871

1. 更新: npm update -g bower

2. cd <your project> && bower init

{
  "name": "bestProjectEvar",
  "version": "1.2.3",
  "main": "./path/to/main.js",
  "dependencies": {
    "jquery": "~1.7.2"
  },
  "devDependencies": {
    "qunit": "1.10.0"
  },
  "ignore": [
    "the/most/useless/of/files.txt",
  ]
}

Bower only cares about six things in the file, though I suppose you could clutter it up with other things if you wanted.

name: the name of the package
version: version of same
main: the name of the “main” file in the package, or an array of names if you specify more than one. This appears to be optional and doesn’t actually seem to do much as far as the behavior of bower is concerned.
dependencies: an object specifying dependencies of the package, with package names as keys, and semver_ versions as values
devDependencies: this is like dependencies, but for things you only need for development
ignore: stuff in your repo that you want bower *not* to install when it installs the package
bower list – shows a nicely-formatted tree view of all thepackages installed in your project directory.
bower search – searches the registry for packages matching a keyword
bower info – show available versions for a package
bower register – lets you register a package with the online registry
bower uninstall – I’ll let you guess what this does

3. bower install angular-bootstrap
就会发现在app 目录下下载了若干JS文件和目录
如果你希望更改的话,使用:

// .bowerrc
{
  "directory": "app/assets/components"
}

4. (RAILS相关)

# config/application.rb

# include Bower components in compiled assets
config.assets.paths << Rails.root.join('app', 'assets', 'components')install 完事儿之后,该如何使用呢?

install 完事儿之后,该如何使用呢?

Using packages
The easiest approach is to use Bower statically, just reference the package's installed components manually using a script tag:
<script src="/bower_components/jquery/index.js"></script>
For more complex projects, you'll probably want to concatenate your scripts or use a module loader. Bower is just a package manager, but there are plenty of other tools -- such as Sprockets and RequireJS -- that will help you do this.

订阅/RSS Feed

Subscribe

分类/category