123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- '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');//提示错误并忽略
- const { series } = require('gulp');
- // 引入静态服务器 browser-sync 使用npm i broswer-sync -g 全局安装
- const broswer = require("browser-sync").create()
- /*路径*/
- var lessPath = "./less/*.less";
- var cssDestPath = "./css";
- var jsPath = "./jssrc/*.js";
- var jsDestPath = "./js";
- var projects = ['.', "page_news",
- "component",
- 'page_about_us',
- "page_bidding_information",
- "page_auction_notice",
- "page_cooperation",
- "page_detailed",
- "page_financial",
- "page_donwload",
- "page_settlein"]
- var lessTasks=[]
- var javascriptTasks=[]
- projects.forEach(projectName => {
- lessTasks.push('less:'+projectName)
- javascriptTasks.push('javascript:'+projectName)
- //编译sass
- gulp.task('less:'+projectName, function () {
- return gulp.src(projectName+"/"+lessPath)
- .pipe(plumber())
- .pipe(less())
- .pipe(mincss())
- .pipe(rename({
- suffix: ".min"
- }))
- .pipe(gulp.dest(projectName+"/"+cssDestPath))
- .pipe(livereload());
- });
- //压缩JS
- gulp.task('javascript:'+projectName, function () {
- return gulp.src(projectName+"/"+jsPath)
- .pipe(plumber())
- .pipe(minjs())
- .pipe(rename({
- suffix: ".min"
- }))
- .pipe(gulp.dest(projectName+"/"+jsDestPath))
- .pipe(livereload())
- })
- });
- gulp.task('less',gulp.parallel(lessTasks))
- gulp.task('javascript',gulp.parallel(javascriptTasks))
- //监测文件
- gulp.task('watch', function () {
- gulp.watch(lessPath, gulp.series("less"));
- gulp.watch(jsPath, gulp.series("javascript"));
- })
- // 开启浏览服务
- gulp.task('browser', function () {
- broswer.init({
- server: "./",
- port: 3000
- })
- })
- // gulp.task('default',function(){
- // livereload.listen();
- // gulp.series(gulp.parallel("less","javascript","watch"));
- // // gulp.run("less","javascript","watch");
- // });
- gulp.task('default', gulp.parallel(function () {
- console.log("----------------")
- livereload.listen();
- }, "less", "javascript", gulp.parallel("watch", "browser")));
|