-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
74 lines (63 loc) · 1.9 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
var gulp = require('gulp'),
concat = require('gulp-concat'), //合并文件
minifycss = require('gulp-minify-css'), //压缩css
htmlmin = require('gulp-htmlmin'), //压缩html
uglify = require('gulp-uglify'), //压缩js
rename = require('gulp-rename'), //重命名
imagemin = require('gulp-imagemin'), //压缩图片
stripDebug = require('gulp-strip-debug'),
del = require('del'); //每次打包清除dist
var config = {
input:{
html:['./tpls/*.html'],
js:['./source/service/*.js', './source/directive/*.js', './source/controller/*.js'], // 有先后的依赖关系
css:['./source/css/*.css'],
images:['./images/*']
},
output:{
html:'./dist/tpls',
css:'./dist/css',
js:'./dist/js',
images:'./dist/images'
}
};
gulp.task('clean',function(){
return del(config.output.html,config.output.css,config.output.js,config.output.images);
});
gulp.task('html', function () {
var options = {
removeComments: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
minifyJS: true,
minifyCSS: true
};
return gulp.src(config.input.html)
.pipe(htmlmin(options))
.pipe(gulp.dest(config.output.html))//gulp dest是输出
});
gulp.task('js', function (done) {
return gulp.src(config.input.js)
.pipe(concat('app.bundle.js'))
.pipe(rename({suffix:'.min'}))
.pipe(uglify())
.pipe(stripDebug())
.pipe(gulp.dest(config.output.js));
});
gulp.task('css', function () {
return gulp.src(config.input.css)
.pipe(rename({suffix:'.min'}))
.pipe(minifycss())
.pipe(concat('app.bundle.css'))
.pipe(gulp.dest(config.output.css));
});
//压缩图片
gulp.task('images', function(){
return gulp.src(config.input.images)
.pipe(imagemin())
.pipe(gulp.dest(config.output.images));
});
gulp.task('default', ['clean', 'html','js','css','images']);