gulp无法完成任务-Gulp4

时间:2019-11-20 03:09:29

标签: javascript gulp

嗨,我对以下内容有疑问:

我收到以下错误。任何想法可能是什么问题?我试图将代码转换为可在GULP 4上使用,但默认设置在1.68s之后完成?: ” 正在启动“默认” ... 开始'compile-scss'... [14:24:05]开始“默认” ... [14:24:05]在1.68毫秒后完成“默认”设置 “

我的代码是:

    /// Include gulp
var gulp = require('gulp');

// Include plugins
var path = require('path');
var sass = require('gulp-sass');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var cleanCSS = require('gulp-clean-css');
var folders = require('gulp-folders');
var imagemin = require('gulp-imagemin');

// Config
var inputFolders =  'src'
var outputFolders = 'public'
var scssInput =     'styles';
var scssOutput =    'styles'
var jsInput =       'scripts';
var jsOutput =      'scripts';
var mediaInput =    'images';
var mediaOutput =   'images';
var backupImageFolder = 'backup-image';

// compile scss into css
gulp.task('compile-scss', folders(inputFolders, function (folder) {
  var processors = [
    autoprefixer()
  ];
  return gulp.src(inputFolders + '/' + folder + '/' + scssInput  + '/*.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(postcss(processors))
    .pipe(cleanCSS({compatibility:'*'}))
    .pipe(gulp.dest(outputFolders + '/' + folder + '/' + scssOutput));
}));

// concatenate and minify js
gulp.task('scripts', folders(inputFolders, function(folder) {
  return gulp.src(inputFolders + '/' + folder + '/' + jsInput + '/*.js')
    // .pipe(concat('scripts.js'))
    .pipe(uglify())
    .pipe(gulp.dest(outputFolders + '/' + folder + '/' + jsOutput));
}));

// deploy any media and losslessly optimise if possible
gulp.task('media', folders(inputFolders, function(folder) {
  return gulp.src([inputFolders + '/' + folder + '/' + mediaInput + '/*', inputFolders + '/' + folder + '/' + mediaInput + '/**/*'])
    .pipe(imagemin())
    .pipe(gulp.dest(outputFolders + '/' + folder + '/' + mediaOutput));
}));

// copy across html
gulp.task('html', folders(inputFolders, function(folder) {
  return gulp.src(inputFolders + '/' + folder + '/*.html')
    .pipe(gulp.dest(outputFolders + '/' + folder))
}));

// copy across back-up image for the banner
gulp.task('copy-backup-image', folders(inputFolders, function(folder) {
  return gulp.src(inputFolders + '/' + folder + '/' + backupImageFolder + '/*' )
  .pipe(gulp.dest(outputFolders + '/' + folder + '/' + backupImageFolder))
}));

// Watch files for changes, run affected tasks
gulp.task('watch', function() {
  gulp.watch([inputFolders + '/*/' + scssInput + '/*.scss'], gulp.series('compile-scss'));
  gulp.watch([inputFolders + '/*/' + scssInput + '/**/*.scss'], gulp.series('compile-scss'));
  gulp.watch([inputFolders + '/*/' + jsInput + '/*.js'], gulp.series('scripts'));
  gulp.watch([inputFolders + '/*/' + mediaInput + '/*'], gulp.series('media'));
  gulp.watch([inputFolders + '/*/' + mediaInput + '/**/*'], gulp.series('media'));
  gulp.watch([inputFolders + '/*/*.html'],  gulp.series('html'));
  gulp.watch([inputFolders + '/*/' + backupImageFolder + '/*'],  gulp.series('copy-backup-image'));
});

// Default task
gulp.task('default', function(done) {
  gulp.series('compile-scss', 'scripts', 'media', 'html', 'copy-backup-image', 'watch');
  done();
})

0 个答案:

没有答案