我在Gulp 4.0中进行迁移时遇到问题,请尝试对其进行更新,但仍然看到错误。
口香糖 assert.js:339 犯错 ^
AssertionError [ERR_ASSERTION]:从未定义任务:tocss
我正在尝试编辑代码以移植到版本4.0,但是仍然收到错误消息,未定义变量tocss,但是如果我在gulpfile.js中安装并定义了依赖项,则该错误
我复制了所有代码,以便您可以帮助我正确构建代码。
var gulp = require('gulp'),
plumber = require('gulp-plumber'),
debug = require('gulp-debug'),
htmlmin = require('gulp-htmlmin'),
map = require('gulp-sitemap'),
jsmin = require('gulp-uglify-es').default,
tocss = require('gulp-scss'),
cssmin = require('gulp-cleancss'),
imagemin = require('gulp-imagemin');
gulp.task('mini', gulp.parallel('htmlmin', 'jsmin', 'imagemin', gulp.series('tocss', 'cssmin')));
gulp.task('all', gulp.series('map'));
gulp.task('default', gulp.series(gulp.parallel('mini','all'), 'watch'));
gulp.task('htmlmin', () => {
return gulp.src('*.html')
.pipe(plumber())
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(debug({verbose: true}))
.pipe(gulp.dest('html_min/'));
});
gulp.task('map', () => {
return gulp.src('*.html', {
read: false
})
.pipe(plumber())
.pipe(map({
siteUrl: 'http://www.donamadorperu.com'
}))
.pipe(debug({verbose: true}))
.pipe(gulp.dest(''));
});
gulp.task('jsmin', () => {
return gulp.src('js/*.js')
.pipe(plumber())
.pipe(jsmin())
.pipe(debug({verbose: true}))
.pipe(gulp.dest('js/min/'));
});
gulp.task('tocss', () => {
return gulp.src('scss/*.scss')
.pipe(plumber())
.pipe(tocss())
.pipe(debug({verbose: true}))
.pipe(gulp.dest('css/'));
});
gulp.task('cssmin', () => {
return gulp.src('css/*.css')
.pipe(plumber())
.pipe(cssmin())
.pipe(debug({verbose: true}))
.pipe(gulp.dest('css/min/'));
});
gulp.task('imagemin', () => {
return gulp.src('img/*.{jpg,jpeg,png,gif}')
.pipe(plumber())
.pipe(imagemin())
.pipe(debug({verbose: true}))
.pipe(gulp.dest('img/img_min/'));
});
gulp.task('watch', () => {
gulp.watch('*.html', gulp.series('htmlmin'));
gulp.watch('*.html', gulp.series('map'));
gulp.watch('js/*.js', gulp.series('jsmin'));
gulp.watch('scss/*.scss', gulp.series('tocss'));
gulp.watch('css/*.css', gulp.series('cssmin'));
gulp.watch('img/*.{jpg,jpeg,png,gif}', gulp.series('imagemin'));
});
我希望社区能够帮助我,我发现了更新的惊喜