Top Banner
2015: A Static Site Generator Odyssey Created by Thomas Jaggi / and Olga Skurativska / @backflip @_olko
46

2015: A static site generator odyssey

Jan 13, 2017

Download

Internet

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 2015: A static site generator odyssey

2015: A Static SiteGenerator OdysseyCreated by Thomas Jaggi / and Olga Skurativska / @backflip @_olko

Page 2: 2015: A static site generator odyssey

Who we areFrontend engineers at

About 150 engineers,distributed over 6 locations

Interdisciplinary departmentwith UX / UI designers

Unic AG

Page 3: 2015: A static site generator odyssey

BasisStatic frontendprototype

Page 4: 2015: A static site generator odyssey

Issue #1:Communication with projectmembers

UX / UI designers

Backend engineers

Project managers

Customers

Page 5: 2015: A static site generator odyssey

 

Page 6: 2015: A static site generator odyssey

Preview serverPresentation of current and previous state of the frontendprototype

Page 7: 2015: A static site generator odyssey

Overview page

Page 8: 2015: A static site generator odyssey

Project page

Page 9: 2015: A static site generator odyssey

Build index page

Page 10: 2015: A static site generator odyssey

Build content page

Page 11: 2015: A static site generator odyssey

Issue #2:Automating frontend routines

Working with templates and partials

Generating CSS (preprocessing SCSS, autoprefixing,minifying)

Generating JavaScript (dependency resolving,concatenating, minifying, linting, unit testing, customizedbuilds of libraries)

Icons and images handling

Watching for changes and livereloading

Page 12: 2015: A static site generator odyssey

Anticipated question:Why didn't you just use anexisting static site generator?

Page 13: 2015: A static site generator odyssey

Our experiencewith Middleman:

Fixed technology stack

Configuration based

Written in Ruby

Page 14: 2015: A static site generator odyssey

Nice to have:JavaScript-based solution

Possibility to plug in different tools

Quick setup of new projects

Page 15: 2015: A static site generator odyssey

Meet Estático!https://github.com/unic/estatico

Page 16: 2015: A static site generator odyssey

Anticipated question:

Why Gulp, not Grunt?

Page 17: 2015: A static site generator odyssey

Estático's Gulp task structureGoal 1: Easy maintenanceWe store tasks in separate files

Page 18: 2015: A static site generator odyssey

Estático's Gulp task structureGoal 2: Make tasks testableDefine task logic as an exportable function

var taskBody = function(config) { return gulp.src(config.src) .pipe(jshint()) .pipe(concat('main.js')) .pipe(uglify()) .pipe(gulp.dest(config.dest)); };

Source and destination paths are parameters

gulp.task(taskName, function() { return taskBody({ src: 'source/*.js', dest: 'build/' });});

Page 19: 2015: A static site generator odyssey

Estático's Gulp task structureGoal 3: WatcherEvery task exports its watch paths

var taskName = 'js', taskConfig = { ... watch: ['source/*.js', 'source/modules/**/*.js'] };

module.exports = { name: taskName config: taskConfig};

Watcher loops through configs

_.each(tasks, function(task) { watch(task.config.watch, function() { gulp.start(task.name); });});

Page 20: 2015: A static site generator odyssey

More automation:ScaffoldingModule create task:

prompts for a module's name

creates module's files

registers module's CSS and JS

Scaffolding tasks have a nicecommand line interface

Page 21: 2015: A static site generator odyssey

More automation:Handling data in a project

Data has to be separate from templates

Templating engine (Handlebars) and JSON solve thatproblem

Page 22: 2015: A static site generator odyssey

Anticipated question:Why Handlebars?

Page 23: 2015: A static site generator odyssey

Handlebars:looks like HTML, is easy to understand

is extendable with custom helpers

is mustache-like

Page 24: 2015: A static site generator odyssey

From JSON to JavaScript objectData becomes reusable

We can modify data before display using JavaScript

Page 25: 2015: A static site generator odyssey

Demo

Page 26: 2015: A static site generator odyssey

Issue #3:Continuous integration (CI)

1. Commit

2. Build (and run tests, code analysis, …)

3. Publish (preview server, artefact storage, …)

Page 27: 2015: A static site generator odyssey

Prerequisites1. Node.js with

2. That's it

Page 28: 2015: A static site generator odyssey

Problem 1:Not all Nodes are created equal

0.12 introduced breaking changes

Packages don't necessarily work in every major version

Page 29: 2015: A static site generator odyssey

$ nvm use (0.12.2)

$ node -v0.12.2

Solution:Version management toolExample: nvm

* When on Windows: nvm-windows

Page 30: 2015: A static site generator odyssey

Problem 2:Platform differences

1. Missing dependencies

2. Different implementations

Page 31: 2015: A static site generator odyssey

Example 1:Missing dependencies

✖ Error: pngquant failed to build, makesure that libpng-dev is installed

✖ Error: /lib/x86_64-linux-gnu/libc.so.6:version ̀GLIBC_2.14' not found

Page 32: 2015: A static site generator odyssey

Example 2:Different implementations (SVG to PNG)

1. Use PhantomJS

2. Discover problem on Windows:Cannot start phantomjs: Phantom didn'trespond within 30 seconds)

3. Use GraphicsMagick

4. Discover problem on OS X: vs.

5. Use PhantomJS on Unix and GraphicsMagick on Windows

6. Discover new problem on Windows

7. Go back to 1.

Page 33: 2015: A static site generator odyssey

Solution:Specify runtime and make itavailable

1. Specify software versions

2. Select your linux flavor

3. Create box (or image)

4. $ vagrant up && vagrant ssh

Page 34: 2015: A static site generator odyssey

Problem 3:npm install  ≠  npm install

npm packages are specified using SemVer

Works fine in theory, doesn't work as fine in practice

Page 35: 2015: A static site generator odyssey

Solution:Lock down dependencies$ npm shrinkwrap

Page 36: 2015: A static site generator odyssey

Problems 4-99:npm

Great piece of software

Amazing team behind it

But: Many edge cases

Page 37: 2015: A static site generator odyssey

Solution:When in doubt: Clear cache$ npm cache clean

Update npm$ npm install -g npm@latest

* When on Windows: npm-windows-upgrade

Page 38: 2015: A static site generator odyssey

Issue #4: Open-sourcing things

When to publish

How (not) to deal with licensing

How (not) to maintain

Page 39: 2015: A static site generator odyssey

When to publishJust get over yourself!

Code will never be perfect

Publish anyway

Improve continuously

Page 40: 2015: A static site generator odyssey

How to deal with licensing

Set up contributor license agreement (CLA) workflow

http://choosealicense.com

Not an actor

Page 41: 2015: A static site generator odyssey

How to maintainSchedule time to take care of contributions

Define responsibilities

Contribute back to other OSS software (report bugs,suggest features, …) ❤

Page 42: 2015: A static site generator odyssey

SummaryAutomate everything!

Create your own set of Gulp tasks!

Open-source it!

Set up a preview server!

Page 43: 2015: A static site generator odyssey

Who is behind all of this?

Page 44: 2015: A static site generator odyssey

Thanks!

Page 45: 2015: A static site generator odyssey

Do youwant to be our friend?

Page 46: 2015: A static site generator odyssey

ContactThomas Jaggi, – [email protected] @backflip

Olga Skurativska, – [email protected] @_olko

Interested in working with us?https://www.unic.com/de/about/career/jobs/development/senior-frontend-engineer-15-08-18.html