Gulp错误找不到具有单数glob的文件

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

将gulp 3更改为4后,当我尝试运行gulp build时收到错误:

Error: File not found with singular glob: /assets/css/argon.css (if this was purposeful, use `allowEmpty` option)

这段代码以前在gulp 3上是可以工作的(正如我被告知的那样),我做了一些修改,以便能够在gulp 4上工作。在所有任务都正确运行后,收到错误消息。

文件位于要查找的位置:

下面是我的gulpfile.js:

var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync').create();
var csscomb = require('gulp-csscomb');
var cleanCss = require('gulp-clean-css');
var cssnano = require('gulp-cssnano');
var composer = require('gulp-uglify/composer');
var concat = require('gulp-concat');
var del = require('del');
var imagemin = require('gulp-imagemin');
var htmlPrettify = require('gulp-html-prettify');
var gulp = require('gulp');
var gulpIf = require('gulp-if');
var gulpRun = require('gulp-run');
var gulpUtil = require('gulp-util');
var npmDist = require('gulp-npm-dist');
var postcss = require('gulp-postcss');
var runSequence = require('gulp4-run-sequence');
// var sass = require('gulp-sass');
var uglifyEs = require('uglify-es');
var uglify = composer(uglifyEs, console);
var rename = require('gulp-rename');
var useref = require('gulp-useref-plus');
var wait = require('gulp-wait');
var sass = require('gulp-sass')(require('sass'));

// Define paths

var paths = {
 dist: {
     base: 'dist',
     img:  'dist/assets/img',
     libs: 'dist/assets/vendor'
 },
 base: {
     base: './',
     node: 'node_modules'
 },
 src: {
     base: './',
     css:  'assets/css',
     html: '**/*.html',
     img:  'assets/img/**/*.+(png|jpg|gif|svg)',
     js:   'assets/js/**/*.js',
     scss: 'assets/scss/**/*.scss'
 }
}

// Compile SCSS

gulp.task('scss', async function() {
return gulp.src(paths.src.scss)
 .pipe(wait(500))
 .pipe(sass().on('error', sass.logError))
 .pipe(postcss([require('postcss-flexbugs-fixes')]))
 .pipe(autoprefixer({
     browsers: ['> 1%']
 }))
 .pipe(csscomb())
 .pipe(gulp.dest(paths.src.css))
 .pipe(browserSync.reload({
     stream: true
 }));
});

// Minify CSS

gulp.task('minify:css', async function() {
return gulp.src([
     paths.src.css + '/argon.css'
 ])
 .pipe(cleanCss())
 .pipe(rename({ suffix: '.min' }))
 .pipe(gulp.dest(paths.dist.base + '/css'))
});

// Concat JS files

gulp.task('concat:js', async function(done) {

 files = [
     paths.src.base + '/assets/js/components/license.js',
     paths.src.base + '/assets/js/components/layout.js',
     paths.src.base + '/assets/js/components/init/*js',
     paths.src.base + '/assets/js/components/custom/*js',
     paths.src.base + '/assets/js/components/maps/*js',
     paths.src.base + '/assets/js/components/charts/*js',
     paths.src.base + '/assets/js/components/vendor/*js'
 ];

 return gulp
     .src(files)
     .pipe(concat("argon.js"))
     .pipe(gulp.dest(paths.dist.base + '/js'));

 done();
});

// Minify JS

gulp.task('minify:js', async function(cb) {
 return gulp.src([
         paths.dist.base + '/js/argon.js'
     ])
     .pipe(uglify())
     .pipe(rename({ suffix: '.min' }))
     .pipe(gulp.dest(paths.dist.base + '/js'))
});

// Live reload

gulp.task('browserSync', async function() {
 browserSync.init({
     server: {
         baseDir: [paths.src.base, paths.base.base]
     },
 })
});

// Watch for changes

gulp.task('watch', gulp.series('browserSync', 'scss', async function() {
 gulp.watch(paths.src.scss, ['scss']);
 gulp.watch(paths.src.js, browserSync.reload);
 gulp.watch(paths.src.html, browserSync.reload);
}));

// Clean

gulp.task('clean:dist', async function() {
 return del.sync(paths.dist.base);
});

// Copy CSS

gulp.task('copy:css', async function() {
 return gulp.src([
     paths.src.base + '/assets/css/argon.css'
 ])
 .pipe(gulp.dest(paths.dist.base + '/css'))
});

// Copy JS

gulp.task('copy:js', async function() {
 return gulp.src([
     paths.src.base + '/assets/js/argon.js'
 ])
 .pipe(gulp.dest(paths.dist.base + '/js'))
});

// Build

gulp.task('build', async function(callback) {
 runSequence('clean:dist', 'scss', 'copy:css', 'copy:js', 'concat:js', 'minify:js', 'minify:css',
     callback);
});

// Default

gulp.task('default', async function(callback) {
 runSequence(['scss', 'browserSync', 'watch'],
     callback
 )
});

任何帮助都将不胜感激:)

ee7vknir

ee7vknir1#

copy:css中,您有以下行:
paths.src.base + '/assets/css/argon.css'
显然你的错误在哪里。问题是你的paths.src.base被定义为
/assets/css/argon.css添加到base: './',因此最终得到
.//assets/css/argon.css请注意前面的两个反斜杠。
去掉/assets/...中的前导反斜杠,并检查代码的其余部分是否存在同样的问题。
此外,由于您使用的是gulp 4,请删除runSequence-请查看gulp.series的文档。

相关问题