1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 'use strict';
- var gulp = require('gulp');//gulp核心
- /*var sass = require('gulp-sass');//编译sass*/
- var less = require('gulp-less');//编译less
- var mincss = require('gulp-clean-css');//压缩css
- var minjs = require('gulp-uglify');//压缩JS
- var rename = require('gulp-rename');//文件重命名
- var watch = require('gulp-watch');//监控文件
- var livereload = require('gulp-livereload');//热更新
- var plumber = require('gulp-plumber');//提示错误并忽略
- /*路径*/
- var lessPath = "./less/*.less";
- var cssDestPath = "./css";
- var jsPath = "./jssrc/*.js";
- var jsDestPath = "./js";
- //编译sass
- gulp.task('less',function(){
- return gulp.src(lessPath)
- .pipe(plumber())
- .pipe(less())
- .pipe(mincss())
- .pipe(rename({
- suffix: ".min"
- }))
- .pipe(gulp.dest(cssDestPath))
- .pipe(livereload());
- });
- //压缩JS
- gulp.task('javascript',function(){
- return gulp.src(jsPath)
- .pipe(plumber())
- .pipe(minjs())
- .pipe(rename({
- suffix:".min"
- }))
- .pipe(gulp.dest(jsDestPath))
- .pipe(livereload())
- })
- //监测文件
- gulp.task('watch',function(){
- gulp.watch(lessPath,gulp.series("less"));
- gulp.watch(jsPath,gulp.series("javascript"));
- })
- // gulp.task('default',function(){
- // livereload.listen();
- // gulp.series(gulp.parallel("less","javascript","watch"));
- // // gulp.run("less","javascript","watch");
- // });
- gulp.task('default',gulp.parallel(function(){
- livereload.listen();
- },"less","javascript","watch"));
|