gulpfile.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict';
  2. var gulp = require('gulp');//gulp核心
  3. /*var sass = require('gulp-sass');//编译sass*/
  4. var less = require('gulp-less');//编译less
  5. var mincss = require('gulp-clean-css');//压缩css
  6. var minjs = require('gulp-uglify');//压缩JS
  7. var rename = require('gulp-rename');//文件重命名
  8. var watch = require('gulp-watch');//监控文件
  9. var livereload = require('gulp-livereload');//热更新
  10. var plumber = require('gulp-plumber');//提示错误并忽略
  11. /*路径*/
  12. var lessPath = "./less/*.less";
  13. var cssDestPath = "./css";
  14. var jsPath = "./jssrc/*.js";
  15. var jsDestPath = "./js";
  16. //编译sass
  17. gulp.task('less',function(){
  18. return gulp.src(lessPath)
  19. .pipe(plumber())
  20. .pipe(less())
  21. .pipe(mincss())
  22. .pipe(rename({
  23. suffix: ".min"
  24. }))
  25. .pipe(gulp.dest(cssDestPath))
  26. .pipe(livereload());
  27. });
  28. //压缩JS
  29. gulp.task('javascript',function(){
  30. return gulp.src(jsPath)
  31. .pipe(plumber())
  32. .pipe(minjs())
  33. .pipe(rename({
  34. suffix:".min"
  35. }))
  36. .pipe(gulp.dest(jsDestPath))
  37. .pipe(livereload())
  38. })
  39. //监测文件
  40. gulp.task('watch',function(){
  41. gulp.watch(lessPath,gulp.series("less"));
  42. gulp.watch(jsPath,gulp.series("javascript"));
  43. })
  44. // gulp.task('default',function(){
  45. // livereload.listen();
  46. // gulp.series(gulp.parallel("less","javascript","watch"));
  47. // // gulp.run("less","javascript","watch");
  48. // });
  49. gulp.task('default',gulp.parallel(function(){
  50. livereload.listen();
  51. },"less","javascript","watch"));