Files
weui/gulpfile.js
2015-11-09 10:47:17 +08:00

86 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 option = {base: 'src'};
var dist = __dirname + '/dist';
gulp.task('source', function(){
gulp.src('src/example/**/*.!(less)', option)
.pipe(gulp.dest(dist))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('styles', ['source'], function () {
gulp.src('src/example/example.less', option)
.pipe(less().on('error', function (e){
console.error(e.message);
this.emit('end');
}))
.pipe(autoprefixer())
.pipe(minify())
.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}', ['source'], function () {
browserSync.reload();
});
});
gulp.task('server', function () {
yargs.p = yargs.p || 8080;
browserSync.init({
server: {
baseDir: "./dist"
},
ui: {
port: yargs.p + 1,
weinre: {
port: yargs.p + 2
}
},
port: yargs.p,
startPath: '/example'
});
});
// 参数说明
// -w: 实时监听
// -s: 启动服务器
// -p: 服务器启动端口默认8080
gulp.task('default', ['release'], function () {
if (yargs.s) {
gulp.start('server');
}
if (yargs.w) {
gulp.start('watch');
}
});