web development tools { starter pack }

34
Web development tools @_francois06 @hugomallet @53JSdev December 2016 University of Nice Sophia Antipolis { starter pack }

Upload: francois-michaudon

Post on 15-Apr-2017

73 views

Category:

Internet


1 download

TRANSCRIPT

Page 1: Web development tools { starter pack }

Web development

tools

@_francois06

@hugomallet@53JSdevDecember 2016University of Nice Sophia Antipolis

{ starter pack }

Page 3: Web development tools { starter pack }

And we love gif !

Page 4: Web development tools { starter pack }

#WhatDoWeNeed?

Web development tools

Page 5: Web development tools { starter pack }

FASTD.R.Y.FLEXIBLE

Page 6: Web development tools { starter pack }

Improve development

Localhost serverLiveReload Package managerModule bundlerSASS with sourcemap...

to focus on the features of your own app

Page 7: Web development tools { starter pack }

Prepare for deployment

Concatenate JS, CSS Minify CSS, HTML, JS, imagesCopy all the files in dist folder

Package your app for differents platforms (apk, ipa, exe, html)

Must be done in one command line

Page 8: Web development tools { starter pack }
Page 9: Web development tools { starter pack }
Page 10: Web development tools { starter pack }

> npm init

> npm install commander

> npm test

> npm publish

#!/usr/bin/env node

const program = require('commander');const pkg = require('./package');

program.version(pkg.version) .option('-n, --name [value]', 'Name') .parse(process.argv);

console.log('Hello ' + program.name);

Page 11: Web development tools { starter pack }

Automate and enhance your workflow

Page 12: Web development tools { starter pack }

npm install -g gulp-cli

npm init

npm install gulp --save-dev

Page 13: Web development tools { starter pack }

Task gulpconst gulp = require('gulp');

gulp.task('build', function() {

// do something...

});

gulp.task('default', 'build', function() {

console.log('default task');

});

# gulpfile.js

> gulp

Starting 'build'

Finished 'build'

Starting 'default'

Finished 'default'

> gulp build

Starting 'build'

Finished 'build'

Terminal

Page 14: Web development tools { starter pack }

streams

gulp

.src('scripts/*.js')

.pipe(applySomething())

.pipe(gulp.dest('dist/scripts'));

Page 15: Web development tools { starter pack }

gulp.task('sass', function() {

return gulp.src('app/styles/main.scss')

.pipe($.sourcemaps.init())

.pipe($.sass({

outputStyle: 'nested', // libsass doesn't support expanded yet

precision: 10,

includePaths: ['.'],

onError: console.error.bind(console, 'Sass error:')

}).on('error',$.sass.logError))

.pipe($.if(production,

$.replace('node_modules/bootstrap-sass/assets/fonts/bootstrap', 'fonts')))

.pipe($.autoprefixer({

browsers: ['last 1 version']

}))

.pipe($.if(production, $.sourcemaps.write('.', {

includeContent: false,

sourceRoot: './'

})))

.pipe(gulp.dest('dist/styles'));

});

Page 16: Web development tools { starter pack }

WATCH & RELOAD

1. Start a server

2. Watch files

3. Reload files in browser

Page 17: Web development tools { starter pack }

const connect = require('connect');

const connectLivereload =

require('connect-livereload');

const gulp = require('gulp');

const serveStatic = require('serve-static');

gulp.task('serve', function() {

var app = connect()

.use(connectLivereload({

port: 35729

}))

.use(serveStatic('app'))

.listen(9000);

});

const livereload = require('gulp-livereload');

gulp.task('watch', ['serve'], function() { livereload.listen();

gulp.watch([

'app/scripts/**/*.js',

'app/images/**/*',

'.tmp/styles/*'

]).on('change', livereload.changed);

gulp.watch(['styles/**/*.{css,scss}'], ['sass']);

});

gulp.task('default', ['watch']);

Serve files Watch files and reload

Page 18: Web development tools { starter pack }

SCSS !$color: blue;

li {// menu linksa {

background: $color;}

}

Page 19: Web development tools { starter pack }

CSS# dist/main.css

li a {background: blue;

}

const gulp = require('gulp');

const sass = require('gulp-sass');

gulp.task('sass', function() {

return gulp.src('app/styles/main.scss')

.pipe(sass())

.pipe(gulp.dest('dist/styles'));

});

Page 20: Web development tools { starter pack }

BE LAZY

“I choose a lazy person to do a hard job.

Because a lazy person will find an easy way

to do it.”

― Bill Gates

Page 21: Web development tools { starter pack }

Be lazy : example const gulp = require('gulp');

const sass = require('gulp-sass');

const debug = require('gulp-debug');

gulp.task('sass', function() {

return gulp.src('app/styles/main.scss')

.pipe(debug())

.pipe(sass())

.pipe(gulp.dest('dist/styles'));

});

const gulp = require('gulp');

const $ = require('gulp-load-plugins')(),

gulp.task('sass', function() {

return gulp.src('app/styles/main.scss')

.pipe($.debug())

.pipe($.sass())

.pipe(gulp.dest('dist/styles'));

});

npm i -D gulp-load-plugins

Page 22: Web development tools { starter pack }

Debug gulp-plumber

Prevent pipe breaking caused by errors from gulp plugins

https://gist.github.com/floatdrop/8269868

gulp-debug

Debug vinyl file streams to see what files are run through your gulp pipeline

Page 23: Web development tools { starter pack }

Let’s require('modules')in the browser

Page 24: Web development tools { starter pack }

Require ?# lib/module.js

exports.multiply = function multiply(a, b) {

return a * b;

}

exports.add = function add(a, b) {

return a + b;

}

# tests/module.js

const assert = require('assert');

const mymath = require('../lib/module');

const multiply = mymath.multiply;

describe('mymath', () => {

describe('#multiply(a, b)', () => {

it('should return 6 with 2 and 3', () => {

assert.equal(6, multiply(2, 3));

assert.equal(6, multiply(3, 2));

});

});

});

Page 25: Web development tools { starter pack }

Browserify : require in the browser !

> npm install -g browserify

> npm install --save jquery

> browserify main.js -o dist/bundle.js

const $ = require('jquery');

const mult = require('./lib/module').multiply;

let $a = $('.num-a');

let $b = $('.num-b');

$('button').on('click', function onClick(event) {

mult($a.val(), $b.val());

});

Terminal # main.js

Page 26: Web development tools { starter pack }

be prepared for

ES6 Modules

export function multiply(a, b) { … }

import { multiply } from './lib/module'

Page 27: Web development tools { starter pack }

+≃

Page 28: Web development tools { starter pack }

ESLintShare style guides !

Avoid mistakes !

# .eslintrc

/* * Extending the code style * of the devs at Airbnb */

{

'extends': 'eslint-config-airbnb'

}

Page 29: Web development tools { starter pack }

{ SOURCEMAPS }

Page 30: Web development tools { starter pack }

> npm publish

Page 31: Web development tools { starter pack }

This is just an overview ...

Build your own gulpfile.js

adapted to your tools and methods !

A sample we made for you : https://github.com/53js/simple-webapp/

Page 32: Web development tools { starter pack }

And now you need to choose a good JavaScript framework http://todomvc.com/

Page 33: Web development tools { starter pack }

Thank you !

https://www.53js.fr

Page 34: Web development tools { starter pack }

Last important thing