forked from Tencent/weui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
84 lines (74 loc) · 2.08 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
var yargs = require('yargs').argv;
var gulp = require('gulp');
var less = require('gulp-less');
var minify = require('gulp-minify-css');
var autoprefixer = require('gulp-autoprefixer');
var rename = require('gulp-rename');
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync');
var dist = __dirname + '/dist';
gulp.task('styles', function () {
var option = {base: 'src'};
gulp.src('src/example/**/*.!(less)', option)
.pipe(gulp.dest(dist))
.pipe(browserSync.reload({stream: true}));
gulp.src('src/example/example.less', option)
.pipe(less().on('error', function (e){
console.error(e.message);
this.emit('end');
}))
.pipe(gulp.dest(dist))
.pipe(browserSync.reload({stream: true}));
gulp.src('src/style/weui.less', option)
.pipe(sourcemaps.init())
.pipe(less().on('error', function (e) {
console.error(e.message);
this.emit('end');
}))
.pipe(sourcemaps.write())
.pipe(autoprefixer())
.pipe(gulp.dest(dist))
.pipe(minify())
.pipe(rename(function (path) {
path.basename += '.min';
}))
.pipe(gulp.dest(dist))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('release', ['styles']);
gulp.task('watch', function () {
gulp.watch('src/**/*.less', ['styles']);
gulp.watch('src/example/**/*.{html,js}', function () {
browserSync.reload();
})
});
gulp.task('server', function () {
browserSync.init({
server: {
baseDir: "./dist"
},
ui: {
port: 8081,
weinre: {
port: 9090
}
},
port: 8080,
startPath: '/example'
});
});
// 参数说明
// -w: 实时监听
// -s: 启动服务器
// -p: 服务器启动端口,默认8080
gulp.task('default', function () {
if (yargs.s) {
gulp.start('server');
}
if (yargs.w) {
gulp.start('release');
gulp.start('watch');
} else {
gulp.start('release');
}
});