-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile-en.js
46 lines (41 loc) · 1.66 KB
/
gulpfile-en.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
var gulp = require('gulp');
var cleanCSS = require('gulp-clean-css');
var htmlmin = require('gulp-html-minifier-terser');
var htmlclean = require('gulp-htmlclean');
// 使用terser压缩js
var terser = require('gulp-terser');
// minify js - gulp-tester
gulp.task('compress', () =>
gulp.src(['./public-en/**/*.js', '!./public-en/**/*.min.js', '!./public-en/**/custom.js','!./public-en/**/custom.js', '!./public-en/sw-dom.js', '!./public-en/bbs/bbs.js'])
.pipe(terser())
.pipe(gulp.dest('./public-en'))
)
//css
gulp.task('minify-css', () => {
return gulp.src('./public-en/**/*.css')
.pipe(cleanCSS({
compatibility: 'ie11'
}))
.pipe(gulp.dest('./public-en'));
});
// 壓縮 public-en 目錄內 html
gulp.task('minify-html', () => {
return gulp.src('./public-en/**/*.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
}))
.pipe(gulp.dest('./public-en'))
});
// 執行 gulp 命令時執行的任務
gulp.task("default", gulp.parallel(
'compress','minify-html', 'minify-css'
));