-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
59 lines (50 loc) · 2.25 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
const gulp = require("gulp");
const less = require("gulp-less");
const rename = require('gulp-rename');
const rm = require("rimraf");
const cleanCSS = require('gulp-clean-css');
const {watch, task, series, parallel} = gulp;
const lessGlob = ["src/**.less","!**/tool.less"];
function swallowError(error){
console.error("已捕获错误:",error.toString());
}
const getLessBuilder = async (src, distName)=>{
await gulp
.src(src)
.pipe(less({}))
.pipe(rename(file=>{
file.basename = `${distName}.uncompressed`;
}))
.pipe(gulp.dest("dist"))
.pipe(
cleanCSS({
backgroundClipMerging: true, // controls background-clip merging into shorthand
backgroundOriginMerging: true, // controls background-origin merging into shorthand
backgroundSizeMerging: true, // controls background-size merging into shorthand
colors: true, // controls color optimizations
ieBangHack: false, // controls keeping IE bang hack
ieFilters: false, // controls keeping IE `filter` / `-ms-filter`
iePrefixHack: false, // controls keeping IE prefix hack
ieSuffixHack: false, // controls keeping IE suffix hack
merging: true, // controls property merging based on understandability
shorterLengthUnits: false, // controls shortening pixel units into `pc`, `pt`, or `in` units
spaceAfterClosingBrace: true, // controls keeping space after closing brace - `url() no-repeat` into `url()no-repeat`
urlQuotes: true, // controls keeping quoting inside `url()`
zeroUnits: true // controls removal of units `0` value
})
)
.on("error",swallowError)
.pipe(rename(function(file){
file.basename = distName;
}))
.pipe(gulp.dest("dist"))
}
gulp.task("build-less",async function(){
await new Promise(resolve=> rm("dist", resolve));
await getLessBuilder("src/dist-index.less","index");
await getLessBuilder("src/dist-lite.less","lite");
await getLessBuilder("src/dist-reset.less","reset");
});
task("watch-less", function () {
watch(lessGlob, series(["build-less"]));
});