1. install Node.js
2.
$ npm install gulp -g
4. create a gulpfile.js at the root of project
var gulp = require('gulp');
gulp.task('default', function() {
// place code for your default task here
});
3.
$ npm install --save-dev gulp
var gulp = require('gulp');
var imagemin = require('gulp-imagemin');
gulp.task('default', function() {
return gulp.src('img/*')
.pipe(imagemin())
.pipe(gulp.dest('min-img'));
});
$ npm install --save-dev gulp-imagemin
var gulp = require('gulp');
var imagemin = require('gulp-imagemin');
var changed = require('gulp-changed');
gulp.task('default', function() {
return gulp.src('img/*')
.pipe(changed('min-img'))
.pipe(imagemin())
.pipe(gulp.dest('min-img'));
});
$ npm install --save-dev gulp-changed
var gulp = require('gulp');
var imagemin = require('gulp-imagemin');
var changed = require('gulp-changed');
gulp.task('img-min', function() {
return gulp.src('img/*')
.pipe(changed('min-img'))
.pipe(imagemin())
.pipe(gulp.dest('min-img'));
});
gulp.task('watch', function(){
gulp.watch('img/*',['img-min']);
});
gulp.task('default', ['watch'] );
var gulp = require('gulp');
var imagemin = require('gulp-imagemin');
var changed = require('gulp-changed');
var sass = require('gulp-sass');
gulp.task('img-min', function() { /* ... */ });
gulp.task('sass', function() {
return gulp.src('sass/*.sass')
.pipe(sass())
.pipe(gulp.dest('css'));
});
gulp.task('watch', function(){
gulp.watch('img/*', ['img-min']);
gulp.watch('sass/*.sass', ['sass']);
});
gulp.task('default', ['watch', 'img-min', 'sass'] );
$ npm install --save-dev gulp-sass
$myColor: #FF3456;
$myMargin: 16px;
.myclass
{
background-color: $myColor;
margin: $myMargin;
div
{
background-color: darken($myColor, 50%);
margin: $myMargin / 2;
}
}
var gulp = require('gulp');
/* ... */
var ts = require('gulp-typescript');
gulp.task('img-min', function() { /* ... */ });
gulp.task('sass', function() { /* ... */ });
gulp.task('ts', function() {
return gulp.src('ts/*.ts')
.pipe(ts())
.pipe(gulp.dest('js'));
});
gulp.task('watch', function(){
gulp.watch('img/*', ['img-min']);
gulp.watch('sass/*.sass', ['sass']);
gulp.watch('ts/*.ts', ['ts']);
});
gulp.task('default', ['watch', 'img-min', 'sass', 'ts'] );
$ npm install --save-dev gulp-typescript
// TypeScript Array
var list:Array<string> = ["A", "B", "C"];
// ES5 Array.map()
// ES6 Arrow Function
var myLength = list.map( s => s.length );
console.log( myLength ); // 3
var gulp = require('gulp');
/* ... */
var mainBowerFiles = require('main-bower-files');
gulp.task('bower-main-file', function(){
return gulp.src(mainBowerFiles())
.pipe(gulp.dest("./lib"));
});
gulp.task('default', [ 'bower-main-file'] );
$ npm install --save-dev main-bower-files
var gulp = require('gulp');
gulp.task('express', function() {
var express = require('express');
var app = express();
app.use(express.static(__dirname));
app.listen(4000);
});
gulp.task('default', ['express'] );
$ npm install --save-dev express
var gulp = require('gulp');
gulp.task('express', function() {
var express = require('express');
var app = express();
app.use(require('connect-livereload')({port: 4002}));
app.use(express.static(__dirname));
app.listen(4000);
});
npm install tiny-lr connect-livereload --save-dev
var tinylr;
gulp.task('livereload', function() {
tinylr = require('tiny-lr')();
tinylr.listen(4002);
});
gulp.task('watch', function() {
gulp.watch('*.html', function(event){
var fileName = require('path').relative(__dirname, event.path);
tinylr.changed({
body: {
files: [fileName]
}
});
});
});
gulp.task('default', ['express', 'livereload', 'watch']);