Gulp Gulp 多任务启动缓慢

whhtz7ly  于 2022-12-08  发布在  Gulp
关注(0)|答案(1)|浏览(198)

我浏览了整个网站,试图找到解决这个问题的方法,但我不完全理解解决方法。我是否做错了什么,导致加载时间变慢?

var gulp = require('gulp');
    jade = require('gulp-jade');
    sass = require('gulp-sass');
    postcss = require('gulp-postcss');
    browserSync = require('browser-sync');
    autoprefixer = require('autoprefixer-core');

gulp.task('sass', function(){
  var processors = [
    autoprefixer
  ];

  return gulp.src('sass/main.scss')
    .pipe(sass())
    .pipe(postcss(processors))
    .pipe(gulp.dest('css'));
});

gulp.task('jade', function() {
  return gulp.src('jade/index.jade')
  .pipe(jade({pretty: true}))
  .pipe(gulp.dest(''));
});

gulp.task('watch', function(){
  browserSync({
    server: {
      baseDir: ''
    }
  });
  gulp.watch('**/*.sass', ['doc-watch']);
  gulp.watch('**/*.jade', ['doc-watch']);
  gulp.watch('**/*.js', ['doc-watch']);
});

gulp.task('doc-watch', ['sass', 'jade'], browserSync.reload);

gulp.task('default', ['doc-watch']);

谢谢你的建议。

ffscu2ro

ffscu2ro1#

'use strict';

//Dependencies
var gulp = require('gulp');
var sass = require('gulp-sass');
var minifyCSS = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var changed = require('gulp-changed');


////////////////////
// - SCSS/CSS
////////////////////

var SCSS_SRC = '.src/Assets/Assets/*.scss';
var SCSS_DEST = './src/Assets/css';

//Compile SCSS
gulp.task('compile_scss', gulp.series(function(){
  gulp.src(SCSS_SRC)
  .pipe(sass().on('error', sass.logError))
  .pipe(minifyCSS())
  .pipe(rename({ suffix: '.min' }))
  .pipe(changed(SCSS_DEST))
  .pipe(gulp.dest(SCSS_DEST));
}));

//Detect changes in SCSS
gulp.task('watch_scss', gulp.series(function(){
  gulp.watch(SCSS_SRC, gulp.series(['compile_scss']))
}));

//Run tasks
gulp.task('default', gulp.series(['watch_scss']));

相关问题