External dependency management with Bower

In addition to using RequireJS or a similar library for managing your code's dependencies, many programmers also use a second tool called Bower (http://bower.io/) to manage their external library dependencies. Much like Python's pip or Node.js's NPM, Bower offers a simple command line interface for easily installing external libraries. It's worth noting that NPM itself can also be used for managing libraries on the client-side, but this tool is designed primarily for server-side developers, whereas Bower is designed primarily for use on the client-side. To install a library, such as jQuery, one would simply run the following command at the command line:

bower install jquery

Multiple Bower dependencies can be stored in a bower.json file, allowing you to install all of your application's dependencies with a single command. Here's an example of what such a file might look like:

{
    "name": "your-project",
    "version": "0.0.1",
    "ignore": [
        "**/*.txt"
    ],
    "dependencies": {
        "backbone": "1.0.0",
        "jquery": "~2.0.0"
    },
     "devDependencies": {
        "mocha": "^1.17.1"
    }
}

As you can see, the preceding file defines the dependencies for your project. It includes Backbone and jQuery but not Underscore; as a dependency of Backbone, Underscore will be downloaded automatically (jQuery isn't technically a dependency of Backbone, as the library will work without it, so we have to require it separately). It also lets us include Mocha as devDependency, which means that it will be downloaded in a development environment but not in a production one. Using a requirements file like this allows you to keep your external libraries out of your source control system and to easily update them when new versions come out. It also allows you to easily manage different builds of these libraries (for instance, the debugging version versus the minified version).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.111.134