gpt4 book ai didi

javascript - gulp 4 的浏览器列表和同步完成问题

转载 作者:行者123 更新时间:2023-12-02 22:29:56 24 4
gpt4 key购买 nike

我正在尝试调试 GULP 文件中的错误。我似乎无法弄清楚我到底应该改变什么。错误如下:

将 Autoprefixer 浏览器选项替换为浏览器列表配置。 在 package.json 或 .browserslistrc 文件中使用 browserslist 键。

使用浏览器选项会导致一些错误。浏览器列表配置 可用于 Babel、Autoprefixer、postcss-normalize 等工具。

如果您确实需要使用选项,请将其重命名为 overrideBrowserslist。

了解更多信息: https://github.com/browserslist/browserslist#readme https://twitter.com/browserslist

[12:20:01] 以下任务未完成:默认、compile-scss[12:20:01] 您是否忘记发出异步完成信号?

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({browsers: ['last 2 versions', 'IE 10', 'Safari 8']})
];
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',
gulp.series(gulp.parallel('compile-scss', 'scripts', 'media', 'html', 'copy-backup-image'), 'watch'));

最佳答案

在您的工作根目录或工作区目录中创建一个 .browserslistrc,其中包含类似以下内容:

# Browsers that we support

last 2 versions
IE 10
Safari 8

然后更改此代码:

var 处理器 = [
autoprefixer({浏览器: ['最后 2 个版本', 'IE 10', 'Safari 8']})
];

简单地说:

var 处理器 = [
自动前缀器()
];

这应该可以消除对浏览器选项的提示。然后运行您的default 任务,看看是否修复了您的'compile-scss' 无法完成错误消息并报告的问题。

<小时/>

现在讨论异步信号问题。该 gulp-folders 插件已经 5 年没有更新了,所以我建议采用不同的方法。

const glob = require('glob');

// this gets an array of matching folders
const folders = glob.sync(inputFolders');

gulp.task('compile-scss', () => {

let stream;

// work on each folder separately
folders.forEach(function (folder) {

stream = gulp.src( inputFolders + '/' + folder + '/' + scssInput + '/*.scss' )

// do your other stuff

.pipe(gulp.dest( outputFolders + '/' + folder + '/' + scssOutput ));
});
return stream;
});

关于javascript - gulp 4 的浏览器列表和同步完成问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58945269/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com