Tech Junkie Blog - Real World Tutorials, Happy Coding!: Use Bower to Get Client Dependencies

Saturday, June 25, 2016

Use Bower to Get Client Dependencies

Bower is a JavaScript tool to get client dependencies in your project using npm packages.

The requirement for bower is that you need to install Node.js first.  You can follow along in the this blog to install node.js, After node.js is installed open the command line and type the following command

npm install -g bower






The command above will install bower in your system globally.  Now we can use bower install packages individually, but the convenience of bower is in the bower.json file.  With the bower.json file we can specify all the dependencies that our project will need in one configuration file.

Here are the steps:

1.  Create a folder call "AngularShoppingApp"

2.  Create a file call bower.json in your favorite text editor

3.  The content of the bower.json file should look like this

{
  "name": "ShoppingApp",
  "private": true,
  "dependencies": {
    "angularjs": "~1.5.7",
    "bootstrap": "~3.3.6"
  }
}

The important thing to look at is the dependencies section.  As you can see we listed out our dependencies in the json file and let bower take care of it for ourselves.
The ~ symbol tells bower to get any version that starts with the numbers after it.  The other notable values are the "name" which is the name of the application.

4.  Now we want to specify the location of where we want the bower components are installed in our application.  For that we want to create the .bowerrc file .  the only variable we want to set in the file "directory" file, which specifies where we want the bower components to be install.  Let's install the bower components in the "js/lib" folder. So in the .bowerrc file type in the following

{
  "directory": "js/lib"
}

4.  Now open up the cmd file and navigate to the folder where the bower.json file is located, and type in the following command

bower install

after you type bower install the JavaScript libraries will be installed in the "js/lib" library


The folder structure of your app should look like the following:


3 comments:

  1. GB WhatsApp apk is not directly available on iPhone just yet but the developers are working on it. Although one may use android emulators to download it. This will allow iOS to run Android applications.

    ReplyDelete
  2. If you really want you can look the other way and not talk about it. Dont give up your morals for anything. This will lead to a sad and unfulfilling life.

    ReplyDelete

Search This Blog