-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
81 lines (73 loc) · 2.83 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
const gulp = require('gulp');
const jshint=require('gulp-jshint');
const clean = require('gulp-clean');
const imagemin = require('gulp-imagemin');
const pngquant = require('imagemin-pngquant');
const cssmin=require('gulp-uglifycss');
const uglify = require('gulp-uglify');
const htmlmin = require('gulp-htmlmin');
const spriter = require('gulp-css-spriter');
gulp.task('jshint', function () {
return gulp.src('dev/js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('clean', function () {
gulp.src(['dist/css/*', 'dist/js/*', 'dist/images/*','dist/images/*/*', 'dist/html/*'], {read: false})
.pipe(clean({force: true}));
});
gulp.task('image', () => {
gulp.src(['dev/images/*','dev/images/*/*'])
.pipe(imagemin({
progressive: true,
svgoPlugins: [
{removeViewBox: false},
{cleanupIDs: false}
],
use: [pngquant()]
}))
.pipe(gulp.dest('dist/images'));
});
gulp.task('css', () =>{
gulp.src('dev/css/*.css')
.pipe(spriter({
// The path and file name of where we will save the sprite sheet
'spriteSheet': './dist/images/spritesheet.png',
// Because we don't know where you will end up saving the CSS file at this point in the pipe,
// we need a litle help identifying where it will be.
'pathToSpriteSheetFromCSS': '../images/spritesheet.png'
})
)
.pipe(cssmin({
"maxLineLen": 80,
"uglyComments":true
}))
.pipe(gulp.dest('dist/css'));
});
gulp.task('html', function () {
var options = {
removeComments: true,//清除HTML注释
collapseWhitespace: true,//压缩HTML
collapseBooleanAttributes: true,//省略布尔属性的值 <input checked="true"/> ==> <input />
removeEmptyAttributes: true,//删除所有空格作属性值 <input id="" /> ==> <input />
removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
minifyJS: true,//压缩页面JS
minifyCSS: true//压缩页面CSS
};
gulp.src('dev/html/*.html')
.pipe(htmlmin(options))
.pipe(gulp.dest('dist/html'));
});
gulp.task('js', function () {
gulp.src('dev/js/*')
.pipe(uglify({
//mangle: true,//类型:Boolean 默认:true 是否修改变量名
mangle: {except: ['require' ,'exports' ,'module' ,'$']},//排除混淆关键字
compress: true,//类型:Boolean 默认:true 是否完全压缩
preserveComments: 'all' //保留所有注释
}))
.pipe(gulp.dest('dist/js'));
});
gulp.task("default",['jshint','clean','html','js','css','image']);
gulp.task("test",['jshint']);