代码拉取完成,页面将自动刷新
/*
* 说明:gulp配置文件
*/
var gulp = require('gulp'),
Less = require('gulp-less'),
cleanCSS = require('gulp-clean-css'),
sourcemaps = require('gulp-sourcemaps'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
pump = require('pump'),
autoprefixer = require('gulp-autoprefixer');
var assets={
less: './src/less/page/*.less',
config: './src/js/config/*.js',
page: './src/js/page/*.js',
util: './src/js/util/*.js'
};
function less (cb){
pump([
gulp.src( './src/less/app.less'),
Less(),
autoprefixer({ browsers: ['last 2 versions'], cascade: false }),
cleanCSS(),
gulp.dest('assets/css')
], cb);
}
function config (cb){
pump([
gulp.src(assets.config),
concat('config.js'),
uglify(),
gulp.dest('assets/js')
], cb);
}
function util (cb){
pump([
gulp.src(assets.util),
concat('util.js'),
uglify(),
gulp.dest('assets/js')
], cb);
}
function page (cb){
pump([
gulp.src(assets.page),
uglify(),
gulp.dest('assets/js/page')
], cb);
}
//编译less
gulp.task('less', function (cb) {
less(cb)
});
//压缩合并config
gulp.task('config', function (cb) {
config(cb)
});
//压缩合并util
gulp.task('util', function (cb) {
util(cb)
});
//压缩page js
gulp.task('page', function (cb) {
page(cb)
});
//监听文件变化
gulp.task('watch',['config', 'util', 'page', 'less'], function(cb){
//监听config文件修改
var configWatcher = gulp.watch(assets.config,['config']);
configWatcher.on('change',function(event){
console.log('Config:File ' + event.path + ' was ' + event.type + ', running tasks...');
});
//监听util文件修改
var utilWatcher = gulp.watch(assets.util,['util']);
utilWatcher.on('change',function(event){
console.log('Util:File ' + event.path + ' was ' + event.type + ', running tasks...');
});
//监听page文件修改
var pageWatcher = gulp.watch(assets.page,['page']);
pageWatcher.on('change',function(event){
console.log('Page:File ' + event.path + ' was ' + event.type + ', running tasks...');
});
//监听less文件修改
var lessWatcher = gulp.watch(assets.less,['less']);
lessWatcher.on('change',function(event){
console.log('Less:File ' + event.path + ' was ' + event.type + ', running tasks...');
});
});
//默认任务
gulp.task('default', ['less','config','util','page']);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。