-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
112 lines (109 loc) · 2.71 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
'use strict'
const gulp = require('gulp')
const cleanCSS = require('gulp-clean-css')
const postcss = require('gulp-postcss')
const stylus = require('gulp-stylus')
const pxToUnits = require('postcss-px2units')
const pxToViewPort = require('postcss-px-to-viewport')
const cssnano = require('cssnano')
const presetenv = require('postcss-preset-env')
const rename = require('gulp-rename')
const toBem = require('postcss-bem-fix')
const toNested = require('postcss-nested')
const bemConfig = {
defaultNamespace: 'ce', // default namespace to use, none by default
style: 'suit', // suit or bem, suit by default,
shortcuts: {
component: 'b',
modifier: 'm',
descendent: 'e'
},
separators: {
namespace: '-',
descendent: '__',
modifier: '--'
}
}
const compile = {
/**
* 编译vw单位文件
*/
cssToVw() {
return gulp
.src("./src/*.styl")
.pipe(stylus())
.pipe(
postcss([
toBem(bemConfig),
toNested(),
pxToViewPort({
viewportWidth: 750, // (Number) The width of the viewport.
viewportHeight: 1334, // (Number) The height of the viewport.
unitPrecision: 3, // (Number) 转换的时候除不尽保留3位小数.
viewportUnit: "vw", // (String) 转换为vw单位.
selectorBlackList: [".ignore", ".hairlines"], // (Array) The selectors to ignore and leave as px.
minPixelValue: 1, // (Number) 小于或等于'1px'不转换为视窗单位.
mediaQuery: false, // (Boolean) Allow px to be converted in media queries.
unitToConvert: "px",
}),
presetenv(),
cssnano({
"cssnano-preset-advanced": {
zIndex: false,
autoprefixer: true,
},
}),
])
)
.pipe(cleanCSS())
.pipe(
rename({
suffix: ".vw",
})
)
.pipe(gulp.dest("./lib"));
},
/**
* build css
*/
cssToRelease() {
return gulp
.src("./src/icon/*.styl")
.pipe(stylus())
.pipe(
postcss([
toBem(bemConfig),
toNested(),
presetenv(),
pxToUnits({
divisor: 1,
targetUnits: "px",
}),
])
)
.pipe(cleanCSS())
.pipe(
rename({
extname: ".css",
})
)
.pipe(gulp.dest("./lib"));
},
/**
* 处理font
*/
copyFont() {
return gulp.src("./src/fonts/**").pipe(gulp.dest("./lib/fonts"));
},
/**
* 处理fontJS
*/
copyFontJS() {
return gulp.src("./src/icon/*.js").pipe(gulp.dest("./lib/"));
},
};
exports.build = gulp.parallel(
compile.cssToRelease,
compile.copyFont,
compile.copyFontJS
)