forked from Tencent/weui-wxss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
65 lines (62 loc) · 1.7 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
var gulp = require('gulp');
var less = require('gulp-less');
var rename = require('gulp-rename');
var postcss = require('postcss');
var postcssGulp = require('gulp-postcss');
var cssnano = require('gulp-cssnano');
var header = require('gulp-header');
var autoprefixer = require('autoprefixer');
var pkg = require('./package.json');
var pxToRpx = postcss.plugin('postcss-px-to-rpx', function () {
return function (root) {
root.replaceValues(/(\d*\.?\d+)px/ig, { fast: 'px' }, (string) => {
return `${parseFloat(string) * 2}rpx`;
})
};
});
gulp.task('watch', function() {
gulp.watch('src/**', ['build:style', 'build:example']);
});
gulp.task('build:style', function() {
var banner = [
'/*!',
' * WeUI v<%= pkg.version %> (<%= pkg.homepage %>)',
' * Copyright <%= new Date().getFullYear() %> Tencent, Inc.',
' * Licensed under the <%= pkg.license %> license',
' */',
''
].join('\n');
gulp
.src(['src/style/**/*.wxss', 'src/example/*.wxss'], { base: 'src' })
.pipe(less())
.pipe(postcssGulp([pxToRpx, autoprefixer(['iOS >= 8', 'Android >= 4.1'])]))
.pipe(
cssnano({
zindex: false,
autoprefixer: false,
discardComments: { removeAll: true }
})
)
.pipe(header(banner, { pkg: pkg }))
.pipe(
rename(function(path) {
path.extname = '.wxss';
})
)
.pipe(gulp.dest('dist'));
});
gulp.task('build:example', function() {
gulp
.src(
[
'src/app.js',
'src/app.json',
'src/app.wxss',
'src/example/**',
'!src/example/*.wxss'
],
{ base: 'src' }
)
.pipe(gulp.dest('dist'));
});
gulp.task('default', ['watch', 'build:style', 'build:example']);