Requirements: nodejs / npm

For the Orinoco river Zend Framework 2 project, Bootstrap will be deployed for a minimal design. One way to get it installed is via Bower (a frontend package manager). Bower requires node.js but only because you need a tool called npm that is shipped with node.js. (Instructions here)

In the XAMPP project discussed earlier move to the main project directory:

cd c:\\xampp/htdocs/zf2project

Then install Bower (v1.3.8):

npm install -g bower

Next create a bower.json file. This file will be created in the same directory as composer.json for clarity. Type:

bower init

Run through the setup procedure. A bower.json file may look like:

{
  "name": "zf2project",
  "version": "1.0.0",
  "authors": [
    "Rik "
  ],
  "description": "Zend Framework Project",
  "license": "MIT",
  "private": true,
  "ignore": [
    "**/.*",
    "node_modules",
    "bower_components",
    "public/components",
    "test",
    "tests"
  ]
}

The default directory is called bower_components but for this project the target is public/components. For this to set up a different file is required called .bowerrc with the following content:

{
  "directory" : "public/components"
}

Next start including the Bootstrap library which also includes jQuery. Type:

bower install bootstrap –save

Bootstrap is now added as a dependency to bower.json and the public/components directory now stores bootstrap (3.2.0) and jQuery (2.1.1).

Updating now is as easy as

bower update

Advantages:
* No need to include css and javascript libraries in the repository
* No need to identify a library by version number. In this setup jQuery is available by:

/components/jquery/src/jquery.js

* Libraries can be automatically updated by “bower update”, for example in a cron job.

Advertisements