-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
51 lines (46 loc) · 1.52 KB
/
Copy pathgulpfile.js
File metadata and controls
51 lines (46 loc) · 1.52 KB
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
// 用到的各个插件
var gulp = require('gulp');
var cleanCSS = require('gulp-clean-css');
var htmlmin = require('gulp-html-minifier-terser');
var htmlclean = require('gulp-htmlclean');
// gulp-tester
var terser = require('gulp-terser');
// 压缩 js
gulp.task('compress', async () => {
gulp.src(['./public/**/*.js', '!./public/**/*.min.js'])
.pipe(terser())
.pipe(gulp.dest('./public'))
});
//压缩 css
gulp.task('minify-css', () => {
return gulp.src(['./public/**/*.css'])
.pipe(cleanCSS({
compatibility: 'ie11'
}))
.pipe(gulp.dest('./public'));
});
//压缩 html
gulp.task('minify-html', () => {
return gulp.src('./public/**/*.html')
.pipe(htmlclean())
.pipe(htmlmin({
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
minifyURLs: true //压缩页面 URL
}))
.pipe(gulp.dest('./public'))
});
// 运行 gulp 命令时依次执行以下任务
gulp.task('default', gulp.parallel(
'compress', 'minify-css', 'minify-html'
))