This presentation will introduce Bower, a powerful package manager for libraries, frameworks, and all things front-end. We will cover basic Bower usage, integration into Grunt & Gulp build processes, tooling, and registering custom packages to be used by anyone.
3. AGENDA
Why do I need this?
Why is it so awesome?
How does it work?
How can I be ultra-awesome with it?
4. Ever felt like this?
DEPENDENCY MANAGEMENT
MESSES
âWTF are we using already?â
âWhat version? Versions?!â
âAm I going to break it?â
âHow can I optimize it?â
8. BOWER KEEPS IT SIMPLE
1. Maintains a dependency manifest.
2. Fetches them when you need it.
3. Tracks dependencies.
4. Integrates with everything.
(NOT A BUILD TOOL LIKE OR
)
12. WHY BOWER TOO?
Bower focuses on client-side dependencies.
1. Abstracts, separates concerns.
2. Uses a flat dependency tree.
3. Lives and breathes Git.
4. Establishes accountability.
(For you & components developers too)
13. STARTING THE AWESOME
Crack open a command shell:
$ npm install âg bower
Use NPM to install Bower globally.
Initialize Bower configuration from your project root folder.
$ myProject bower init
Prepare for a bunch of questions.
If you have NPM configured, many defaults are taken from package.json.
14. THE BOWER.JSON MANIFAST
{
"name": "bower-power",
"version": â1.0.0â,
"description": "Bower Power! Supercharging Front-End Manageability",
"main": â",
"authors": ["Eric Carlisle eric@ericcarlisle.comâ],
"license": "MIT",
"keywords": ["Bowerâ, âBower Trainingâ],
"homepage": "https://github.com/ecarlisle/bower-power",
"moduleType": [],
"private": true,
"ignore": ["**/.*â, "node_modulesâ, "bower_componentsâ, "testâ, "testsâ],
}
Included in your applications as well as the dependencies you will install.
15. (THEREâS ALSO .BOWERRC)
{
"directory": "app/components/",
"analytics": false,
"timeout": 300000,
"registry": {
"search": ["https://my-bower-server.local",
âhttps://bower.herokuapp.comâ]
}
}
Fit Bower to some app & environment requirements.
17. INSTALLING DEPENDENCIES
# install by name
$ bower install jquery
# By (Github) shortcut
$ bower install twbs/bootstrap
# By GitHub and Subversion endpoints (SSH, HTTPS, HTTP)
$ bower install git@github.com:Modernizr/Modernizr.git
# By URL
$ bower install http://http://bower.io/img/bower-logo.png
# By folder
$ bower install ~/assets/stylesheets/theme3/variables.sass
⊠and several, several ways to choose versions.
There are many installation optionsâŠ
19. THE BOWER_COMPONENTS FOLDER
âą Usually gets the dependencyâs entire GitHub
repo.
âą Sometimes results in positive discovery (Hey,
look!)
âą Empowered to use whatever you need.
âą Many ways to integrate needed files into your
20. TRACK WHAT WE NEED!
# install for production use.
$ bower install jquery --save
# Install for testing, debugging, development purposes only.
$ bower install modernizr --save-dev
"dependencies": { "jquery": "~2.1.4" },
"devDependencies": { "modernizr": â~3.1.0"},
Production or Dev?
Then in bower.json:
27. BUILD & REGISTER A BOWER
PACKAGE
âą Have a working GitHub repository.
âą Please donât squat dependency names.
âą Make certain your bower.json is solid!
# Indicate package name and Github endpoint.
$ bower register my-package https://github.com/you/my-package.git
http://bower.io/search/Bower Registry:
Bower is named after the bowerbird, a family of birds where males build a structure [the bower] and decorate it with sticks and brightly coloured objects in an attempt to attract a mate.
BECAUSEâŠ
You start asking yourself these questions.
CODING ON QUICKSAND
1. Unmaintainable situation.
2. Common to a lot of projects, especially those that have history, multiple owners.
You start asking yourself:
1. âThis is impossible. I just need to rewrite this.â
2. There are clever ways to unravel and existing mess
a. Scalable and Modular Architecture for CSS (Mina Markham â fantastic session name)
b. What Iâll be presenting isnât so much about unraveling an existing mess.
c. Instead itâs about (being lucky and) getting a clean start and do our best to maintain it.
d. Essentially preventing your X-Wing from getting stuck on a swamp.
Youâve probably heard this advice before to avoid all kinds or production trouble.
Do you all know what the KISS approach is? Just call it out if so.
Well, I heard the one that most people use. In a situation where Iâm managing a dependency nightmare, itâs more likeâŠ
STUNNINGLY SIMPLE:
Special to achieve excellence this way.
1. If you havenât already read The Toyota Way, I recommend.
2. Mantra of Kaizen or âContinuous Improvement.â
3. A big part of that is in creating and maintaining cleaner, simpler methodologies that were initially seemingly impossible.
When it happens:
1. Itâs initially funny because you just donât believe it or trust it â âNothing is ever this easy. Whatâs the catch?â
2. Once you start believing, we start having some gleeful âMy life just got a lot betterâ
3. Definite pride component â you turned what was once elusive, bewildering, and frustrating into something easy.
BUT TO MAKE THIS HAPPEN, YOU HAVE TO MAINTAIN THIS OVER TIME.
And, of course, thereâs the bottom line factor.
- Examples of dependencies
Funny note â you use NPM, the Node.JS package installer to install Bower.
I can hear the voice of all my DevOps colleagues
âLet me get this right? Youâre using a package manager to install a package manager.â
Now remember, at this point youâre already using NPM so the amount of âORâ in this equation is relative.
I say âUse them bothâ â which is fairly controversial and a topic of many opinions.
At first this seems contradictory because you might be saying to yourself:
âEric, you just told me to keep things simple and here you are using both.â
ButâŠ
Note: By making this decision, we havenât affected a projectâs client-side footprint yet.
âWhy do I want to have two different manifests for dependencies?â
Separating Cioncerns:
1. This is an opportunity for abstraction, ultimately organization.
2. Lot unlike deciding how you want to separate files in a folder tree.
Flat Dependency Tree:
1. âOne version to rule them allâ - In the end, youâre have only one version of each dependency.
2. This is a huge concern for a front-end developer.
3. Note â recently NPM now has flat-tree capability â BUT I again defer to #1.
Lives and Breathes Git:
1. There are many git-related versioning choices that work very well.
2. In addition to selecting a repo â branch, tag, commit.
Accountability:
1. Since you have a flat dependency tree and one version of each dependency, your ultimately responsible for the version that works for you.
2. This also goes for people that develop the dependencies youâre using. They want to make sure that theyâre also tracking their dependency resolutions.
Many Questions:
Some defaults are taken from package package.json.
Keep in mind â some questions apply to the authoring of a bower package, so all may not apply.
Fields:
You donât need them all filled out.
Notice âprivate = trueâ
For dependencies you install, these fields can be more important:
Versioning
Dependency tracking (Backbone has a dependency on Underscore)
INSTALL FILES â REAL EXAMPLE
WEâRE STILL NOT SENDING BYTES TO YOUR SITE
Entire GitHub Repo:
Sometimes the natural reaction to this is
Only the ones you need:
This can differ from resource to resource.
jQuery â I just need jQuery.min.js and a sourcemap.
Bootstrap â I make just want variables.less and grid.less to get scaffolding on my site.
Integration:
Build tools
Build platforms like grunt and gulp.
Another Node module like Bower Installer.
.gitignore:
No need to keep these files around all the time.
Keep up with the versions you specify.
Entire GitHub Repo:
Sometimes the natural reaction to this is:
âWhy do I need the ENTIRE repoâ
âAm I also putting entire Git repos in my projectâ
Only the ones you need:
This can differ from resource to resource.
jQuery â I just need jQuery.min.js and a sourcemap.
Bootstrap â I make just want variables.less and grid.less to get scaffolding on my site.
Integration:
Build tools
Build platforms like grunt and gulp.
Another Node module like Bower Installer.
.gitignore:
No need to keep these files around all the time.
Keep up with the versions you specify.
RUN GULP BUILD1
Important for you
Most of what weâre using now comes out of the Node runtime.
1. Bower-installer â command-line tool.
2. Bower â API that you can use within your own Node applications.
3.