19
SỬ DỤNG GULP TRONG PHÁT TRIỂN THEME NGUYỄN VĂN ĐƯỢC – LAPTRINH.SENVIET.ORG

Sử dụng Gulp trong phát triển theme

Embed Size (px)

Citation preview

Page 1: Sử dụng Gulp trong phát triển theme

SỬ DỤNG GULP TRONG PHÁT TRIỂN THEMENGUYỄN VĂN ĐƯỢC – LAPTRINH.SENVIET.ORG

Page 2: Sử dụng Gulp trong phát triển theme

CONTENT• Why we should change.• How to use Gulp.• What plugins should be used.

Page 3: Sử dụng Gulp trong phát triển theme

DEVELOPMENT BUILDCODE

COMPILE CODE

COMPRESS IMAGES

CLEAN FILES

UPDATE CHANGELOG

VERSION

DOCCUMENT

ZIP

CODE

COMPILE CODE

BROWSER ON PC

BROWSER ON MOBILE

Page 4: Sử dụng Gulp trong phát triển theme

BUILD CODE

COMPILE CODE

COMPRESS IMAGES

REMOVE FILES

UPDATE CHANGELOG

BUMB VERSION

UPDATE DOCCUMENT

ZIP

Page 5: Sử dụng Gulp trong phát triển theme

WE HATE• Do things repeatedly.• Many tedious task.• Waste of time.• Complex config.

Page 6: Sử dụng Gulp trong phát triển theme

WE LOVE• SASS, ES6.• Optimize image.• More time to do exciting task.• Do less, get more.

Page 7: Sử dụng Gulp trong phát triển theme

TASK RUNNER

Page 8: Sử dụng Gulp trong phát triển theme

TASK RUNNER

Page 9: Sử dụng Gulp trong phát triển theme

Config: easier to readSpeed: FastPlugin: 2670 pluginsPersonal Interest

Page 10: Sử dụng Gulp trong phát triển theme

GO WITH GULP BUILD

DEVELOPMENTconfig tasks

gulp dev

code

gulp build

Page 11: Sử dụng Gulp trong phát triển theme

INSTALL GULP

Install nodejs Install gulp cli

Install gulpConfig task

$ npm install –g gulp-cli $ mkdir my-project $ cd my-project $ npm install gulp --save-dev $ >> gulpfile.js

Page 12: Sử dụng Gulp trong phát triển theme

PROJECT STRUCTURE gulptheme |-- dev | |-- fonts | |-- scss | | `-- main.scss | |-- js | | |-- mergable | | | |-- share-dialog.js | | | `-- script.js | | `-- customizer.js | `-- img | |-- logo.png | `-- banner.png |-- css |-- js |-- img |-- inc |-- languages |-- doccuments |-- template-parts |-- gulpfile.js |-- node_modules |-- style.css |-- index.php `-- functions.php

Page 13: Sử dụng Gulp trong phát triển theme

THE PLUGIN NEEDED• gulp-sass• gulp-concat• gulp-autoprefixer• gulp-uglify• gulp-plumber• browser-sync

• gulp-imagemin• gulp-zip

Page 14: Sử dụng Gulp trong phát triển theme

PLUGIN $ npm install gulp-sass gulp-autoprefixer –save-dev-------------------------------------------------- 1 const sass = require('gulp-sass'); 2 const autoprefixer = require('gulp-autoprefixer'); 3 4 gulp.task('sass', function() { 5 return gulp.src(scssFiles) 6 .pipe(plumber({ errorHandler: onError })) 7 .pipe(sass()) 8 .pipe(autoprefixer()) 9 .pipe(gulp.dest("css")) 10 .pipe(browserSync.stream()); 11 });

SASSIMAGEJACASCRIPTZIP

Page 15: Sử dụng Gulp trong phát triển theme

PLUGIN $ npm install gulp-imagemin –save-dev-------------------------------------------------- 1 const imagemin = require('gulp-imagemin'); 2 const plumber = require('gulp-plumber'); 3 4 gulp.task(’image', function() { 5 return gulp.src(imageFiles) 6 .pipe(plumber({ errorHandler: onError })) 7 .pipe(imagemin()) 8 .pipe(gulp.dest('img')); 9 });

SASSIMAGEJACASCRIPTZIP

Page 16: Sử dụng Gulp trong phát triển theme

PLUGIN $ npm install gulp-concat –save-dev-------------------------------------------------- 1 const concat = require('gulp-concat'); 2 const plumber = require('gulp-plumber'); 3 4 gulp.task(‘js-vendor ', function() { 5 return gulp.src(jsFiles) 6 .pipe(plumber({ errorHandler: onError })) 7 .pipe(concat(‘vendor.js’)) 8 .pipe(uglify()) 9 .pipe(gulp.dest(’js')); 10 });

SASSIMAGEJACASCRIPTZIP

Page 17: Sử dụng Gulp trong phát triển theme

PLUGINSASSIMAGEJACASCRIPTZIP

Page 18: Sử dụng Gulp trong phát triển theme

HỎI ĐÁ[email protected]

Page 19: Sử dụng Gulp trong phát triển theme

CẢM ƠN CÁC BẠNLAPTRINH.SENVIET.ORG