for modern Web-Applications Build-System and Development ... · Download Dependencies via bower...

30
Grunt, Gulp & fabs Build-System and Development-Workflow for modern Web-Applications

Transcript of for modern Web-Applications Build-System and Development ... · Download Dependencies via bower...

Page 1: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

Grunt, Gulp & fabs

Build-System and Development-Workflowfor modern Web-Applications

Page 2: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

Philipp BurgmerSoftware Engineer / Consultant / TrainerFocus: Frontend, Web Technologies

WeigleWilczek [email protected]

ABOUT ME

Page 3: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

WeigleWilczek / W11kSoftware Design, Development & MaintenanceConsulting, Trainings & Project Kickoff

Web Applications with AngularJSNative Rich Clients with Eclipse RCP

ABOUT US

Page 4: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

HOW DO YOU START A NEW WEB-APP?

Page 5: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

edit, switch, refresh, test, switch, edit, switch, refresh, test, switch,edit, switch, refresh, test, switch, edit, switch, refresh, test, switch,edit, switch, refresh, test, switch, edit, switch, refresh, test, switch,edit, switch, refresh, test, switch, edit, switch, refresh, test, switch,edit, switch, refresh, test, switch, edit, switch, refresh, test, switch,edit, switch, refresh, test, switch, edit, switch, refresh, test, switch,edit, switch, refresh, test, switch, edit, switch, refresh, test, switch,edit, switch, refresh, test, switch, edit, switch, refresh, test, switch,edit, switch, refresh, test, switch, edit, switch, refresh, test, switch,...

AND HOW DOES IT LOOK LIKEAFTER ONE NIGHT OF

Page 6: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

and no structure in sight

A LOT OF FILES TO MANAGE

Page 7: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

43 Dependencies to other Libraries169 JavaScript Files112 HTML Templates...

AFTER 3 MONTHS

Page 8: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

Manage Dependencies to 3th Party Libraries(Versioning, Conflicts, Download and Inclusion)Include Own JavaScript and CSS FilesStructure and Modularize CodeToo Much Overhead During DevelopmentFind Even Simple Errors Only at Runtime

PROBLEMS

Page 9: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

SOLUTION?THE RIGHT TOOLS MAKE ALL THE DIFFERENCE!

(http://www.nodejs.org)

Runtime forDev Tools

(http://www.gruntjs.com)

Task Runner

Bower(http://www.bower.io)

DependencyManagement

Page 10: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

Command Line ToolNode PackageInstall Binary via npm install -g bowerNo Project Specific Version

BOWERA PACKAGE MANAGER FOR THE WEB

Page 11: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

Define Dependencies in bower.json{ "name": "fabs-presentation", "dependencies": { "angular": "1.2.16", "twbs-bootstrap-sass": "3.1.1", "w11k-slides": "0.4.1" }}

Download Dependencies via bower installHalf the Problem Remains: bower Does Not Manage InclusionHint: Use Fixed Versions Within a Project and Variable Within a Library

BOWERA PACKAGE MANAGER FOR THE WEB

Page 12: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

Command Line ToolLets You Automate Almost EverythingSplit into 2 Node PackagesInstall Binary Globally via npm install -g grunt-cliDefine Dependency to Project Specific Version in package.jsonInstall Locally via npm install

GRUNTTHE JAVASCRIPT TASK RUNNER

Page 13: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

Configure Your Tasks and Targets in Gruntfile.jsEverything Is a Plugin (via NPM and package.json )Countless Plugins AvailableTasks and Configuration Are Pure JavaScriptRegister Custom Tasks in Gruntfile.js ,No Need to Write a Plugin

GRUNTTHE JAVASCRIPT TASK RUNNER

Page 14: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

var grunt = require('grunt');

module.exports = function () { grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-connect');

grunt.registerTask('dev', ['watch', 'connect:dev']); grunt.registerTask('default', ['dev']);

grunt.initConfig({ watch: { src: { files: ['js/**/*.js', '!js/**/*.test.js'] }}, connect: { dev: { options: { port: 9000 }}}});};

SHORTEN DEV-LIFECYCLEWITH LIVERELOAD

Page 15: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

var indexHtmlTask = function () { var jsFiles = utils.filterForJS(this.filesSrc);

grunt.file.copy('src/index.html', 'build-output/index.html', { process: function (contents) { return grunt.template.process(contents, { data: { scripts: jsFiles }}); } });};

grunt.registerMultiTask('indexHtml', 'Process index.html template', indexHtmlTask);

<% scripts.forEach(function ( file ) { %><script type="text/javascript" src="<%= file %>"></script><% }); %>

indexHtml: { dev: { files: ['js/**.*.js', '!js/**/*.test.js'] }}

INCLUDE JAVASCRIPT FILESWITH CUSTOM TASK

Page 16: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

Substitute for CompilerSyntax CheckCoding Rules ValidationStatic Code Analysis

watch: { src: { files: ['js/**/*.js', '!js/**/*.test.js'], tasks: ['jshint:src'] }}

A JAVASCRIPT CODE QUALITY TOOL

Page 17: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

TestingSASS and/or LESS SupportUsing Mock-Data During DevelopmentRunning Frontend with Real Backend

BUT WHAT ABOUT

Page 18: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

Karma & grunt-karma for Unit/Spec TestsProtractor & grunt-protractor for End-2-End Testsgrunt-contrib-sass & grunt-contrib-less

NPM Packages starting with grunt-*Plugin Overview at gruntjs.com/plugins (http://gruntjs.com/plugins)

More than 2800 Plugins, but a Lot of Duplicates

NO PROBLEMTHERE ARE PLUGINS FOR EVERYTHING

Page 19: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

ConcatenationMinificationCache BustingRunning Tests Against Minified Code

THERE IS STILL MORE TO DOBEFORE WE CAN DEPLOY OUR APP

Page 20: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

Project Specific BuildHuge Gruntfile.jsTask DependenciesHard to Do It RightSame Problems as with Ant

THE REAL PROBLEMS

Page 21: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

github.com/w11k/fabs (https://github.com/w11k/fabs)

Inspired by ng-boilerplate (https://github.com/ngbp/ngbp)

Based on Our Best PracticesConfigurableExtendable via Lifecycle-HooksGrunt Based

FABSFABULOUS ANGULARJS BUILD SYSTEM

Page 22: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

Manage Frontend Dependencies with BowerDev-Mode with Server, Proxies and LiveReloadSASS and LESS SupportSpec and End-2-End TestsMocks for Tests and Dev-ModeProject- and Developer-ConfigurationBuild and Serve Distribution incl. Cache Busting

FEATURES

Page 23: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

fabs-boilerplate (https://github.com/w11k/fabs-boilerplate)

This PresentationReal World Projectfabs (https://github.com/w11k/fabs)

DEMO

Page 24: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

Highly Interdependent TasksHard to MaintainHard to Extend (Even With Hooks)Grunt Is Slow (Slower than ...)

FABS & GRUNT PROBLEMS

Page 25: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

gulpjs.com (http://gulpjs.com)

Uses Streams Instead fo Temp FilesRuns Independent Tasks 'Parallel'Code Over ConfigurationNode Package: Install with npm install -g gulpPlugins Are Regular Node Packages

GULP.JS

Page 26: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

var gulp = require('gulp'), rename = require('gulp-rename'), concat = require('gulp-concat'), uglify = require('gulp-uglify');

gulp.task('process-scripts', function() { return gulp.src('src/scripts/*.js') .pipe(concat('1.0.1/main.js')) .pipe(gulp.dest('dest/scripts/')) .pipe(rename({suffix: '.min'})) .pipe(uglify()) .pipe(gulp.dest('dest/scripts/'))});

gulp.task('watch', function() { gulp.watch('src/scripts/*.js', ['process-scripts'])});

PROCESS JAVASCRIPT WITH GULP

Page 27: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

A Lot of Small Tools / Plugins, Each for a Specific TaskDifficult to Keep Track of All These Tools / PluginsNo De-Facto Standard Build Tool like Maven for JavaImpossible to Write One for All Web-Appsfabs for AngularJS ApplicationsWorking on a Gulp Port of fabs

CONCLUSION

Page 28: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

MEET THE SPEAKER

@ Speaker LoungeSecond Floor Directly About Reception

Page 29: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions

Philipp [email protected]

www.w11k.com (http://www.w11k.com)

www.thecodecampus.de (http://www.thecodecampus.de)

Page 30: for modern Web-Applications Build-System and Development ... · Download Dependencies via bower install Half the Problem Remains: bower Does Not Manage Inclusion Hint: Use Fixed Versions