What is the recommended way to add third party library

What is the recommended way to add third party library? Do I just simply copy the codes into js folder or there is better way to do it?

1 Like

Use Bower, it’s made for exactly this purpose.

I believe Ionic creates a bower.json for you if you’ve used the Ionic CLI to create your project. If not, just run bower init to get started.

Now you can install any package mentioned on Bower’s website by using bower install, similar to how NPM works.

For example, if you want to install Angular localForage you use: bower install angular-localforage --save.

Using --save will add it to your Bower.json, so if someone else checks out your project they’ll only have to run bower install to get all the project’s dependencies (again, just like NPM and its package.json.)

By default Bower will install everything to a folder called bower_components. You can change this by creating a .bowerrc file and specifying a directory value, like so:

{
  "directory": "www/lib"
}

Make sure to add the Bower directory to your .gitignore! The only things you should check in is your bower.json and .bowerrc files.

Hope this helps :slight_smile:

6 Likes

thank you very much!

@gki is right, however, you can also just using Ionic CLI with command like:

$ ionic add [component name]

For example, the command $ ionic add ngCordova will make ionic install ngCordova into the www/lib path(see .bowerrc),and then update the bower.json like using bower install ngCordova --save-dev:

{
  "name": "your_project_name",
  "private": "true",
  "devDependencies": {
    "ionic": "driftyco/ionic-bower#1.0.0-beta.14",
    "ngCordova": "~0.1.11-alpha"
  }
}
4 Likes

Hi, what if I want to use npm and not bower ? I cannot reference node_modules in my index.html can I ?