-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
128 lines (93 loc) · 2.73 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
var gulp = require('gulp');
// minify js
var uglify = require('gulp-uglify');
var pump = require('pump');
// minify css
var cleanCSS = require('gulp-clean-css');
// rename
var rename = require('gulp-rename');
// concat js
var concat = require('gulp-concat');
// concat css
var concatcss = require('gulp-concat-css');
// sourcemaps
var sourcemaps = require('gulp-sourcemaps');
// js hint
var jshint = require('gulp-jshint');
// concatreplace
var htmlreplace = require('gulp-html-replace');
// gulp-useref
var useref = require('gulp-useref');
// gulp-if
var gulpif = require('gulp-if');
// del
var del = require('del');
// web server
var webserver = require('gulp-webserver');
// minify concat
var dist_path = 'dist';
// src path
var src_path = 'src';
gulp.task('dev_server',function(){
return gulp.src(src_path)
.pipe(webserver({
livereload:true,
directoryListing:false,
open:true
}));
});
gulp.task('dist_server',function(){
return gulp.src(dist_path)
.pipe(webserver({
livereload:true,
directoryListing:false,
open:true
}));
});
gulp.task('clean', function(){
return del([dist_path+'/**/*']);
});
gulp.task('init',['clean'],function(){
return gulp.src([src_path+'/**/*'])
.pipe(gulp.dest(dist_path));
});
gulp.task('minify-js', function(cb){
return gulp.src(src_path+'/js/*.js')
.pipe(concat('concatenated.js'))
.pipe(gulp.dest(dist_path+'/js'))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(gulp.dest(dist_path+'/js'));
});
gulp.task('minify-css', function(){
return gulp.src(src_path+'/css/*.css')
.pipe(concatcss('concatenated.css'))
.pipe(gulp.dest(dist_path+'/css'))
.pipe(cleanCSS({debug:true}, function(details){
console.log(details.name + ': ' + details.stats.originalSize);
console.log(details.name + ': ' + details.stats.minifiedSize);
}))
.pipe(rename({suffix:'.min'}))
.pipe(gulp.dest(dist_path+'/css'));
});
gulp.task('lint', function(){
return gulp.src([src_path+'/js/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('html-replace',['minify-css','minify-js'], function(){
return gulp.src(dist_path+'/*.html')
.pipe(htmlreplace({
js:'js/concatenated.min.js',
css:'css/concatenated.min.css'
}))
.pipe(gulp.dest(dist_path+'/'));// html 替换后的目录
});
gulp.task('html-useref', function () {
return gulp.src(dist_path+'/*.html')
.pipe(useref())
.pipe(gulpif('*.js', uglify()))
.pipe(gulpif('*.css', cleanCSS()))
.pipe(gulp.dest('dist'));
});
gulp.task('default', ['html-useref']);