BanksySan
BanksySan

Reputation: 28500

Should I copy files from bower_components of reference them there?

After installing BackboneJS, jQuery etc I have a very large bower_components directory.

├───.idea
│   ├───runConfigurations
│   └───scopes
└───app
    ├───bower_components
    │   ├───backbone
    │   ├───jquery
    │   │   ├───dist
    │   │   └───src
    │   │       ├───ajax
    │   │       │   └───var
    │   │       ├───attributes
    │   │       ├───core
    │   │       │   └───var
    │   │       ├───css
    │   │       │   └───var
    │   │       ├───data
    │   │       │   └───var
    │   │       ├───effects
    │   │       ├───event
    │   │       ├───exports
    │   │       ├───manipulation
    │   │       │   └───var
    │   │       ├───queue
    │   │       ├───sizzle
    │   │       │   ├───dist
    │   │       │   └───test
    │   │       │       ├───data
    │   │       │       └───unit
    │   │       ├───traversing
    │   │       │   └───var
    │   │       └───var
    │   └───underscore
    ├───css
    └───js

What is best practice to reference these? e.g directly, Grunt task to copy bits to the main app, or put the bower_componects inside the ~/app directory?

Upvotes: 1

Views: 2070

Answers (2)

yerforkferchips
yerforkferchips

Reputation: 1985

Don't copy them over to your app - that completely defies the intent of a package manager like Bower! By doing so, you'd take control over these files away from your package manager - and then you're left in the same state as before, manually having to copy over files every time with an update of these dependencies.

Just reference the files inside the bower_components/ directory directly (in your HTML, most likely). If you don't like that location or name, you can have bower put your components some place else, see .bowerrc doc: http://bower.io/docs/config/


I can think of a use for only using specific files from your bower_components directory - but only at build time:

If you write a grunt task that runs only at deploy time and strips away all unused files from the bower_components directory, that of course makes sense and does not go against the idea of a package manager, because it only happens on each deploy, a point when the package manager has no responsibilities.

The only problem you might get with this approach is if you have it end up copying files over to a different directory - because then you'd have to change the references to all files from bower_components before deploying, too. The easy solution is to not duplicate files, but instead, only delete the ones you don't need.

Upvotes: 3

Kuba Jagoda
Kuba Jagoda

Reputation: 5547

Just leave them in bower_components and refer proper files inside your index.html file. You can do this manually, or use tools like grunt wiredep to do this for you automatically.

Upvotes: 0

Related Questions