-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
94 lines (82 loc) · 3.27 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// referencees: https://markpop.github.io/2014/09/17/Gulp%E5%85%A5%E9%97%A8%E6%95%99%E7%A8%8B/#
var gulp = require('gulp'),
minifycss = require('gulp-clean-css'), //minify css
jshint = require('gulp-jshint'),//js code check
uglify = require('gulp-uglify'),//compressing js code
imagemin = require('gulp-imagemin'),
livereload = require('gulp-livereload'),
rename = require('gulp-rename'),
notify = require('gulp-notify'),
del = require('del'),
// cheerio = require('gulp-cheerio'),
replace = require('gulp-replace'),
fs = require('fs');
gulp.task('styles', function(){
return gulp.src('src/css/*.css')
// .pipe(rename({suffix:'.min'})) //think rename is better, but I need to modidy the links in html files
.pipe(minifycss())
.pipe(gulp.dest('dist/css'))
.pipe(notify({message: 'style task compeleted'}));
});
gulp.task('view-styles', function(){
return gulp.src('src/views/css/*.css')
.pipe(minifycss())
.pipe(gulp.dest('dist/views/css'))
.pipe(notify({message: 'view-style task compeleted'}));
});
gulp.task('scripts', function() {
return gulp.src('src/js/perfmatters.js')
.pipe(uglify())
.pipe(gulp.dest('dist/js'))
.pipe(notify({ message: 'scripts task compeleted'}));
});
gulp.task('view-scripts', function() {
return gulp.src('src/views/js/*.js')
.pipe(uglify())
.pipe(gulp.dest('dist/views/js'))
.pipe(notify({ message: 'view-scripts task compeleted'}));
});
gulp.task('images', function() {
return gulp.src('src/img/*')
.pipe(imagemin({optimizationLevel: 3, progressive: true, interlaced: true}))
.pipe(gulp.dest('dist/img'))
.pipe(notify({ message: "images task compeleted"}));
});
gulp.task('view-images', function() {
return gulp.src('src/views/images/*')
.pipe(imagemin({optimizationLevel: 3, progressive: true, interlaced: true}))
.pipe(gulp.dest('dist/views/images'))
.pipe(notify({ message: "view-images task compeleted"}));
});
gulp.task('html', function() {
return gulp.src('src/*.html')
.pipe(gulp.dest('dist'));
});
gulp.task('view-html', function() {
return gulp.src('src/views/pizza.html')
.pipe(gulp.dest('dist/views'));
});
gulp.task('inlineCSS', function() {
return gulp.src('src/index.html')
.pipe(replace(/<link href="css\/style.css" rel="stylesheet">/, function(s) {
var style = fs.readFileSync('src/css/style.css', 'utf-8');
return '<style>\n' + style + '\n</style>';
}))
.pipe(gulp.dest('dist'));
});
gulp.task('clean', function(cb) {
del(['dist/css', 'dist/js', 'dist/img','dist/views/css', 'dist/views/js','dist/views/images'], cb);
});
gulp.task('default', function() {
gulp.start('styles', 'scripts', 'images', 'view-styles', 'view-scripts', 'view-images', 'html', 'view-html');
});
gulp.task('watch', function() {
gulp.watch('css/*css',['styles']);
gulp.watch('js/perfmatters.js', ['scripts']);
gulp.watch('images/*', ['images']);
gulp.watch('views/css/*css', ['views-styles']);
gulp.watch('views/js/perfmatters.js', ['views-scripts']);
gulp.watch('views/images/*', ['view-images']);
livereload.listen();
gulp.watch(['dist/**']).on('change', livereload.changed);
});