Bower & Grunt - A practical workflow

Riccardo Coppola
Riccardo CoppolaSenior UI developer um lastminute.com
Bower & Grunt 
A practical workflow 
riccardo coppola about.me/riccardocoppola
Workflow step 1: 
Bower 
Manage front end dependencies
What?
Web sites are made of lots of things — 
frameworks, libraries, assets, utilities, and 
rainbows. Bower manages all these things for 
you.
Why?
Declutter your lib/vendor folder 
Too often we end up with 5 different versions of 
the same library (jQuery is an always-working 
example...). 
Which one are we actually using?
Dependency management 
No more downloads from ten different 
websites to get your dependencies. 
No more version mismatch problems.
Automate dependency management 
$ bower install 
That’s it
vs 
● Flexible: install from Bower 
registry, GitHub, zip, fs location 
● created solely for the front-end 
and optimized with that in mind 
● flat dependency tree (just one 
lib for each type), good for 
front-end related stuff 
● Most commonly used for 
managing Node.js modules 
● works for the front-end too when 
combined with Browserify 
● nested dependency tree (size 
heavy), good for server side 
modules
How?
Install Bower 
$ npm install -g bower 
Bower requires Node, npm and Git.
Search for a package 
http://bower.io/docs/api/#search 
bower search <package>
Install a package 
# registered package (specific version) 
$ bower install jquery#1.2.3 
# GitHub shorthand 
$ bower install desandro/masonry 
http://bower.io/docs/api/#install 
# Git endpoint 
$ bower install git://github.com/user/package.git 
# URL 
$ bower install http://example.com/script.jsv
Maintaining dependencies 
# install package and add it to bower.json 
dependencies 
$ bower install <package> --save 
# install package and add it to bower.json 
devDependencies 
$ bower install <package> --save-dev
bower.json (bower.json : bower = package.json : npm) 
{ 
"name": "my-project", 
"version": "1.0.0", 
"main": "path/to/main.css", 
"ignore": [ 
".jshintrc", 
"**/*.txt" 
], 
"dependencies": { 
"<name>": "<version>", 
"<name>": "<folder>", 
"<name>": "<package>" 
}, 
"devDependencies": { 
"<test-framework-name>": "<version>" 
} 
}
Is it enough? 
Bower is just a tool, helps us organize front 
end dependencies and keeps track of versions.
What we get 
➔ CSS and JS in the same folder 
➔ docs/ tests/ src/ minified versions and sourcemaps 
are all not needed 
➔ Bower components folder can grow if not cleaned
What we want 
➔ separated vendor folders for CSS and JS 
➔ single, non minified version of every lib, nothing else 
➔ clean vendor folder containing just used libs and only 
one version
Workflow step 2: 
grunt-bowercopy 
Scrupulously manage file locations for 
bower dependencies.
Why 
➔ Consistently positions your dependencies where you 
want them in your repository. 
➔ Conveniently facilitates tracking your dependencies 
without committing the entire Bower components folder. 
➔ Has the potential to reduce build times dramatically. 
➔ By default, runs bower install for you
https://www.npmjs.org/package/grunt-bowercopy 
$ npm install grunt-bowercopy --save-dev
grunt/bowercopy.js 
js: { 
options: { 
destPrefix: 'public/js/vendor 
}, 
files: { 
'jquery.js': 'jquery/jquery.js', 
'require.js': 'requirejs/require.js' 
}, 
}, 
sass: { 
options: { 
destPrefix: 'public/css/vendor 
}, 
files: { 
'bootstrap': 'bootstrap-sass-official/bootstrap.js' 
}, 
}, 
...
Workflow step 3: 
grunt-contrib-clean 
Clear files and folders
https://www.npmjs.org/package/grunt-contrib-clean 
$ npm install grunt-contrib-clean --save-dev
grunt/clean.js 
{ 
vendor: ["public/css/vendor/*", "public/js/vendor/*"] 
}
Everything together
aliases.js 
{ 
vendor: ["clean:vendor", "bowercopy:js", "bowercopy:sass"] 
}
If you commit your dependencies 
1. .gitignore the Bower component folder 
2. Add a hook on git pre-commit and run ‘grunt 
vendor’ as part of your pre-commit workflow 
3. Push your public/css/vendor & public/js/vendor
If you DO NOT commit your 
dependencies 
1. .gitignore the Bower component folder, 
public/css/vendor & public/js/vendor 
2. Have your CI run ‘npm install’ as first step of the front 
end workflow 
3. Modify your package.json
package.json 
{ 
"name": "myApp", 
"version": "0.1.0", 
... 
"scripts": { 
"postinstall": "./node_modules/grunt/bin/grunt vendor" 
}, 
... 
}
That’s all folks!
1 von 31

Recomendados

Grunt and Bower von
Grunt and BowerGrunt and Bower
Grunt and BowerGeorge Estebe
1.2K views10 Folien
Production Ready Javascript With Grunt von
Production Ready Javascript With GruntProduction Ready Javascript With Grunt
Production Ready Javascript With GruntXB Software, Ltd.
4.6K views54 Folien
Introduction to Express and Grunt von
Introduction to Express and GruntIntroduction to Express and Grunt
Introduction to Express and GruntPeter deHaan
10.7K views17 Folien
Bower - A package manager for the web von
Bower - A package manager for the webBower - A package manager for the web
Bower - A package manager for the webLarry Nung
847 views76 Folien
Preprocessor Workflow with Grunt von
Preprocessor Workflow with GruntPreprocessor Workflow with Grunt
Preprocessor Workflow with GruntVlad Filippov
10.8K views39 Folien
Grunt to automate JS build von
Grunt to automate JS buildGrunt to automate JS build
Grunt to automate JS buildTejaswita Takawale
5.1K views11 Folien

Más contenido relacionado

Was ist angesagt?

Grunt.js and Yeoman, Continous Integration von
Grunt.js and Yeoman, Continous IntegrationGrunt.js and Yeoman, Continous Integration
Grunt.js and Yeoman, Continous IntegrationDavid Amend
30.8K views63 Folien
Front-end development automation with Grunt von
Front-end development automation with GruntFront-end development automation with Grunt
Front-end development automation with Gruntbenko
5.2K views36 Folien
Bower power von
Bower powerBower power
Bower powerEric Carlisle
2.2K views28 Folien
Yeoman von
YeomanYeoman
YeomanJames Cryer
6.2K views25 Folien
Advanced front-end automation with npm scripts von
Advanced front-end automation with npm scriptsAdvanced front-end automation with npm scripts
Advanced front-end automation with npm scriptsk88hudson
2.9K views53 Folien
Npm scripts von
Npm scriptsNpm scripts
Npm scripts정윤 김
1.5K views71 Folien

Was ist angesagt?(20)

Grunt.js and Yeoman, Continous Integration von David Amend
Grunt.js and Yeoman, Continous IntegrationGrunt.js and Yeoman, Continous Integration
Grunt.js and Yeoman, Continous Integration
David Amend30.8K views
Front-end development automation with Grunt von benko
Front-end development automation with GruntFront-end development automation with Grunt
Front-end development automation with Grunt
benko5.2K views
Advanced front-end automation with npm scripts von k88hudson
Advanced front-end automation with npm scriptsAdvanced front-end automation with npm scripts
Advanced front-end automation with npm scripts
k88hudson2.9K views
Npm scripts von 정윤 김
Npm scriptsNpm scripts
Npm scripts
정윤 김1.5K views
GDG Kraków - Intro to front-end automation using bower.js & grunt.js von Dominik Prokop
GDG Kraków - Intro to front-end automation using bower.js & grunt.jsGDG Kraków - Intro to front-end automation using bower.js & grunt.js
GDG Kraków - Intro to front-end automation using bower.js & grunt.js
Dominik Prokop1.2K views
Continuous Integration for front-end JavaScript von Lars Thorup
Continuous Integration for front-end JavaScriptContinuous Integration for front-end JavaScript
Continuous Integration for front-end JavaScript
Lars Thorup6.4K views
Let Grunt do the work, focus on the fun! [Open Web Camp 2013] von Dirk Ginader
Let Grunt do the work, focus on the fun! [Open Web Camp 2013]Let Grunt do the work, focus on the fun! [Open Web Camp 2013]
Let Grunt do the work, focus on the fun! [Open Web Camp 2013]
Dirk Ginader20.7K views
How we maintain 200+ Drupal sites in Georgetown University von Ovadiah Myrgorod
How we maintain 200+ Drupal sites in Georgetown UniversityHow we maintain 200+ Drupal sites in Georgetown University
How we maintain 200+ Drupal sites in Georgetown University
Ovadiah Myrgorod2.5K views
What makes me "Grunt"? von Fabien Doiron
What makes me "Grunt"? What makes me "Grunt"?
What makes me "Grunt"?
Fabien Doiron3.6K views
Grunt - The JavaScript Task Runner von Mohammed Arif
Grunt - The JavaScript Task RunnerGrunt - The JavaScript Task Runner
Grunt - The JavaScript Task Runner
Mohammed Arif6.3K views
Packing for the Web with Webpack von Thiago Temple
Packing for the Web with WebpackPacking for the Web with Webpack
Packing for the Web with Webpack
Thiago Temple835 views

Destacado

Ftr - Revisão técnica formal von
Ftr - Revisão técnica formalFtr - Revisão técnica formal
Ftr - Revisão técnica formalThalita Chaves
3.1K views1 Folie
Unit testing of java script and angularjs application using Karma Jasmine Fra... von
Unit testing of java script and angularjs application using Karma Jasmine Fra...Unit testing of java script and angularjs application using Karma Jasmine Fra...
Unit testing of java script and angularjs application using Karma Jasmine Fra...Samyak Bhalerao
1.1K views17 Folien
Insights on Protractor testing von
Insights on Protractor testingInsights on Protractor testing
Insights on Protractor testingDejan Toteff
1.3K views24 Folien
Publish Subscribe pattern - Design Patterns von
Publish Subscribe pattern - Design PatternsPublish Subscribe pattern - Design Patterns
Publish Subscribe pattern - Design PatternsRutvik Bapat
10.7K views14 Folien
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp von
Optimising Your Front End Workflow With Symfony, Twig, Bower and GulpOptimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Optimising Your Front End Workflow With Symfony, Twig, Bower and GulpMatthew Davis
52.6K views144 Folien
Publish and Subscribe von
Publish and SubscribePublish and Subscribe
Publish and SubscribeAlexandru Badiu
3.6K views16 Folien

Destacado(20)

Ftr - Revisão técnica formal von Thalita Chaves
Ftr - Revisão técnica formalFtr - Revisão técnica formal
Ftr - Revisão técnica formal
Thalita Chaves3.1K views
Unit testing of java script and angularjs application using Karma Jasmine Fra... von Samyak Bhalerao
Unit testing of java script and angularjs application using Karma Jasmine Fra...Unit testing of java script and angularjs application using Karma Jasmine Fra...
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Samyak Bhalerao1.1K views
Insights on Protractor testing von Dejan Toteff
Insights on Protractor testingInsights on Protractor testing
Insights on Protractor testing
Dejan Toteff1.3K views
Publish Subscribe pattern - Design Patterns von Rutvik Bapat
Publish Subscribe pattern - Design PatternsPublish Subscribe pattern - Design Patterns
Publish Subscribe pattern - Design Patterns
Rutvik Bapat10.7K views
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp von Matthew Davis
Optimising Your Front End Workflow With Symfony, Twig, Bower and GulpOptimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Matthew Davis52.6K views
Protractor framework – how to make stable e2e tests for Angular applications von Ludmila Nesvitiy
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
Ludmila Nesvitiy4.4K views
Introduction to Angular 2 von Trung Vo Tuan
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
Trung Vo Tuan1.6K views
Functional Reactive Programming with RxJS von stefanmayer13
Functional Reactive Programming with RxJSFunctional Reactive Programming with RxJS
Functional Reactive Programming with RxJS
stefanmayer1340.4K views
Tipos de Organigramas / ASIGNACION I / O y M IUTAJS von Gustavo Pinedo
Tipos de Organigramas / ASIGNACION I / O y M IUTAJSTipos de Organigramas / ASIGNACION I / O y M IUTAJS
Tipos de Organigramas / ASIGNACION I / O y M IUTAJS
Gustavo Pinedo355 views
Otp authentication scheme based on ECC von POOJA MEHTA
Otp authentication scheme based on ECCOtp authentication scheme based on ECC
Otp authentication scheme based on ECC
POOJA MEHTA553 views
G10 Science Q1 von Jm Olaybar
G10 Science Q1G10 Science Q1
G10 Science Q1
Jm Olaybar613 views
Nota%20exam%20hadith[1] von yatie1977
Nota%20exam%20hadith[1]Nota%20exam%20hadith[1]
Nota%20exam%20hadith[1]
yatie1977325 views
The Avalon Media System: Implementation and Community von Avalon Media System
The Avalon Media System: Implementation and CommunityThe Avalon Media System: Implementation and Community
The Avalon Media System: Implementation and Community
Hybrid air conditioner von Amr Badra
Hybrid air conditioner Hybrid air conditioner
Hybrid air conditioner
Amr Badra269 views

Similar a Bower & Grunt - A practical workflow

Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools von
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsCool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsRyan Weaver
54.9K views178 Folien
Angular Part 3 (Basic knowledge) von
Angular Part 3 (Basic knowledge)Angular Part 3 (Basic knowledge)
Angular Part 3 (Basic knowledge)Rohit Singh
54 views6 Folien
ENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScript von
ENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScriptENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScript
ENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScriptHoracio Gonzalez
619 views74 Folien
Bower introduction von
Bower introductionBower introduction
Bower introductionOleksii Prohonnyi
578 views25 Folien
ENIB 2015-2016 - CAI Web - S01E01- La forge JavaScript von
ENIB 2015-2016 - CAI Web - S01E01- La forge JavaScriptENIB 2015-2016 - CAI Web - S01E01- La forge JavaScript
ENIB 2015-2016 - CAI Web - S01E01- La forge JavaScriptHoracio Gonzalez
585 views75 Folien
PHP on Heroku: Deploying and Scaling Apps in the Cloud von
PHP on Heroku: Deploying and Scaling Apps in the CloudPHP on Heroku: Deploying and Scaling Apps in the Cloud
PHP on Heroku: Deploying and Scaling Apps in the CloudSalesforce Developers
1.9K views40 Folien

Similar a Bower & Grunt - A practical workflow(20)

Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools von Ryan Weaver
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsCool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Ryan Weaver54.9K views
Angular Part 3 (Basic knowledge) von Rohit Singh
Angular Part 3 (Basic knowledge)Angular Part 3 (Basic knowledge)
Angular Part 3 (Basic knowledge)
Rohit Singh54 views
ENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScript von Horacio Gonzalez
ENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScriptENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScript
ENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScript
Horacio Gonzalez619 views
ENIB 2015-2016 - CAI Web - S01E01- La forge JavaScript von Horacio Gonzalez
ENIB 2015-2016 - CAI Web - S01E01- La forge JavaScriptENIB 2015-2016 - CAI Web - S01E01- La forge JavaScript
ENIB 2015-2016 - CAI Web - S01E01- La forge JavaScript
Horacio Gonzalez585 views
Distributing UI Libraries: in a post Web-Component world von Rachael L Moore
Distributing UI Libraries: in a post Web-Component worldDistributing UI Libraries: in a post Web-Component world
Distributing UI Libraries: in a post Web-Component world
Rachael L Moore553 views
Docker module 1 von Liang Bo
Docker module 1Docker module 1
Docker module 1
Liang Bo603 views
Web development - technologies and tools von Yoann Gotthilf
Web development - technologies and toolsWeb development - technologies and tools
Web development - technologies and tools
Yoann Gotthilf1.1K views
Extending Build to the Client: A Maven User's Guide to Grunt.js von Petr Jiricka
Extending Build to the Client: A Maven User's Guide to Grunt.jsExtending Build to the Client: A Maven User's Guide to Grunt.js
Extending Build to the Client: A Maven User's Guide to Grunt.js
Petr Jiricka2K views
Django dev-env-my-way von Robert Lujo
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-way
Robert Lujo941 views
The Modern Developer Toolbox von Pablo Godel
The Modern Developer ToolboxThe Modern Developer Toolbox
The Modern Developer Toolbox
Pablo Godel2.6K views
Improving build solutions dependency management with webpack von NodeXperts
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpack
NodeXperts248 views
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond von DrupalDay
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
DrupalDay924 views
Once upon a time, there were css, js and server-side rendering von Andrea Giannantonio
Once upon a time, there were css, js and server-side renderingOnce upon a time, there were css, js and server-side rendering
Once upon a time, there were css, js and server-side rendering
Streamline your development environment with docker von Giacomo Bagnoli
Streamline your development environment with dockerStreamline your development environment with docker
Streamline your development environment with docker
Giacomo Bagnoli1.8K views

Último

Page Object Model von
Page Object ModelPage Object Model
Page Object Modelartembondar5
7 views5 Folien
aATP - New Correlation Confirmation Feature.pptx von
aATP - New Correlation Confirmation Feature.pptxaATP - New Correlation Confirmation Feature.pptx
aATP - New Correlation Confirmation Feature.pptxEsatEsenek1
225 views6 Folien
Mobile App Development Company von
Mobile App Development CompanyMobile App Development Company
Mobile App Development CompanyRichestsoft
6 views6 Folien
Transport Management System - Shipment & Container Tracking von
Transport Management System - Shipment & Container TrackingTransport Management System - Shipment & Container Tracking
Transport Management System - Shipment & Container TrackingFreightoscope
6 views3 Folien
Google Solutions Challenge 2024 Talk pdf von
Google Solutions Challenge 2024 Talk pdfGoogle Solutions Challenge 2024 Talk pdf
Google Solutions Challenge 2024 Talk pdfMohdAbdulAleem4
47 views17 Folien
Techstack Ltd at Slush 2023, Ukrainian delegation von
Techstack Ltd at Slush 2023, Ukrainian delegationTechstack Ltd at Slush 2023, Ukrainian delegation
Techstack Ltd at Slush 2023, Ukrainian delegationViktoriiaOpanasenko
7 views4 Folien

Último(20)

aATP - New Correlation Confirmation Feature.pptx von EsatEsenek1
aATP - New Correlation Confirmation Feature.pptxaATP - New Correlation Confirmation Feature.pptx
aATP - New Correlation Confirmation Feature.pptx
EsatEsenek1225 views
Mobile App Development Company von Richestsoft
Mobile App Development CompanyMobile App Development Company
Mobile App Development Company
Richestsoft 6 views
Transport Management System - Shipment & Container Tracking von Freightoscope
Transport Management System - Shipment & Container TrackingTransport Management System - Shipment & Container Tracking
Transport Management System - Shipment & Container Tracking
Freightoscope 6 views
Google Solutions Challenge 2024 Talk pdf von MohdAbdulAleem4
Google Solutions Challenge 2024 Talk pdfGoogle Solutions Challenge 2024 Talk pdf
Google Solutions Challenge 2024 Talk pdf
MohdAbdulAleem447 views
predicting-m3-devopsconMunich-2023-v2.pptx von Tier1 app
predicting-m3-devopsconMunich-2023-v2.pptxpredicting-m3-devopsconMunich-2023-v2.pptx
predicting-m3-devopsconMunich-2023-v2.pptx
Tier1 app14 views
JioEngage_Presentation.pptx von admin125455
JioEngage_Presentation.pptxJioEngage_Presentation.pptx
JioEngage_Presentation.pptx
admin1254559 views
Top-5-production-devconMunich-2023.pptx von Tier1 app
Top-5-production-devconMunich-2023.pptxTop-5-production-devconMunich-2023.pptx
Top-5-production-devconMunich-2023.pptx
Tier1 app10 views
Automated Testing of Microsoft Power BI Reports von RTTS
Automated Testing of Microsoft Power BI ReportsAutomated Testing of Microsoft Power BI Reports
Automated Testing of Microsoft Power BI Reports
RTTS13 views
How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile... von Stefan Wolpers
How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...
How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...
Stefan Wolpers49 views
Streamlining Your Business Operations with Enterprise Application Integration... von Flexsin
Streamlining Your Business Operations with Enterprise Application Integration...Streamlining Your Business Operations with Enterprise Application Integration...
Streamlining Your Business Operations with Enterprise Application Integration...
Flexsin 5 views
Advanced API Mocking Techniques Using Wiremock von Dimpy Adhikary
Advanced API Mocking Techniques Using WiremockAdvanced API Mocking Techniques Using Wiremock
Advanced API Mocking Techniques Using Wiremock
Dimpy Adhikary5 views

Bower & Grunt - A practical workflow

  • 1. Bower & Grunt A practical workflow riccardo coppola about.me/riccardocoppola
  • 2. Workflow step 1: Bower Manage front end dependencies
  • 4. Web sites are made of lots of things — frameworks, libraries, assets, utilities, and rainbows. Bower manages all these things for you.
  • 6. Declutter your lib/vendor folder Too often we end up with 5 different versions of the same library (jQuery is an always-working example...). Which one are we actually using?
  • 7. Dependency management No more downloads from ten different websites to get your dependencies. No more version mismatch problems.
  • 8. Automate dependency management $ bower install That’s it
  • 9. vs ● Flexible: install from Bower registry, GitHub, zip, fs location ● created solely for the front-end and optimized with that in mind ● flat dependency tree (just one lib for each type), good for front-end related stuff ● Most commonly used for managing Node.js modules ● works for the front-end too when combined with Browserify ● nested dependency tree (size heavy), good for server side modules
  • 10. How?
  • 11. Install Bower $ npm install -g bower Bower requires Node, npm and Git.
  • 12. Search for a package http://bower.io/docs/api/#search bower search <package>
  • 13. Install a package # registered package (specific version) $ bower install jquery#1.2.3 # GitHub shorthand $ bower install desandro/masonry http://bower.io/docs/api/#install # Git endpoint $ bower install git://github.com/user/package.git # URL $ bower install http://example.com/script.jsv
  • 14. Maintaining dependencies # install package and add it to bower.json dependencies $ bower install <package> --save # install package and add it to bower.json devDependencies $ bower install <package> --save-dev
  • 15. bower.json (bower.json : bower = package.json : npm) { "name": "my-project", "version": "1.0.0", "main": "path/to/main.css", "ignore": [ ".jshintrc", "**/*.txt" ], "dependencies": { "<name>": "<version>", "<name>": "<folder>", "<name>": "<package>" }, "devDependencies": { "<test-framework-name>": "<version>" } }
  • 16. Is it enough? Bower is just a tool, helps us organize front end dependencies and keeps track of versions.
  • 17. What we get ➔ CSS and JS in the same folder ➔ docs/ tests/ src/ minified versions and sourcemaps are all not needed ➔ Bower components folder can grow if not cleaned
  • 18. What we want ➔ separated vendor folders for CSS and JS ➔ single, non minified version of every lib, nothing else ➔ clean vendor folder containing just used libs and only one version
  • 19. Workflow step 2: grunt-bowercopy Scrupulously manage file locations for bower dependencies.
  • 20. Why ➔ Consistently positions your dependencies where you want them in your repository. ➔ Conveniently facilitates tracking your dependencies without committing the entire Bower components folder. ➔ Has the potential to reduce build times dramatically. ➔ By default, runs bower install for you
  • 21. https://www.npmjs.org/package/grunt-bowercopy $ npm install grunt-bowercopy --save-dev
  • 22. grunt/bowercopy.js js: { options: { destPrefix: 'public/js/vendor }, files: { 'jquery.js': 'jquery/jquery.js', 'require.js': 'requirejs/require.js' }, }, sass: { options: { destPrefix: 'public/css/vendor }, files: { 'bootstrap': 'bootstrap-sass-official/bootstrap.js' }, }, ...
  • 23. Workflow step 3: grunt-contrib-clean Clear files and folders
  • 24. https://www.npmjs.org/package/grunt-contrib-clean $ npm install grunt-contrib-clean --save-dev
  • 25. grunt/clean.js { vendor: ["public/css/vendor/*", "public/js/vendor/*"] }
  • 27. aliases.js { vendor: ["clean:vendor", "bowercopy:js", "bowercopy:sass"] }
  • 28. If you commit your dependencies 1. .gitignore the Bower component folder 2. Add a hook on git pre-commit and run ‘grunt vendor’ as part of your pre-commit workflow 3. Push your public/css/vendor & public/js/vendor
  • 29. If you DO NOT commit your dependencies 1. .gitignore the Bower component folder, public/css/vendor & public/js/vendor 2. Have your CI run ‘npm install’ as first step of the front end workflow 3. Modify your package.json
  • 30. package.json { "name": "myApp", "version": "0.1.0", ... "scripts": { "postinstall": "./node_modules/grunt/bin/grunt vendor" }, ... }