node.js - 当我尝试在 cmment 线上运行 gulp 时,gulp 4.0.0 显示错误
问题描述
我正在尝试制作一个新项目,我在这里使用gulpfile.ja
代码
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const sass = require('gulp-sass');
// Compile SASS
gulp.task('sass', function(){
return gulp.src(['node_modules/bootstrap/scss/bootstrap.scss', 'src/scss/*.scss'])
.pipe(sass())
.pipe(gulp.dest("src/css"))
.pipe(browserSync.stream());
});
// Move JS Files to SRC
gulp.task('js', function(){
return gulp.src(['node_modules/bootstrap/dist/js/bootstrap.min.js', 'node_modules/jquery/dist/jquery.min.js', 'node_modules/tether/dist/js/tether.min.js'])
.pipe(gulp.dest("src/js"))
.pipe(browserSync.stream());
});
// Watch SASS & Serve
gulp.task('serve', ['sass'], function(){
browserSync.init({
server: "./src"
});
gulp.watch(['node_modules/bootstrap/scss/bootstrap.scss', 'src/scss/*.scss'], ['sass']);
gulp.watch("src/*.html").on('change', browserSync.reload);
});
// Move Font Awesome Fonts folder to src
gulp.task('fonts', function(){
return gulp.src('node_modules/font-awesome/fonts/*')
.pipe(gulp.dest("src/fonts"));
});
// Move font awesome css file
gulp.task('fa', function(){
return gulp.src('node_modules/font-awesome/css/font-awesome.min.css')
.pipe(gulp.dest("src/css"));
});
gulp.task('default', ['js', 'serve', 'fa', 'fonts']);
但是当我gulp
在我的命令行上运行时,这里显示一个错误,例如
assert.js:60
throw new errors.AssertionError({
^
AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask] (D:\PracticeJob\bs4practice\node_modules\undertaker\lib\set-task.js:10:3)
at Gulp.task (D:\PracticeJob\bs4practice\node_modules\undertaker\lib\task.js:13:8)
at Object.<anonymous> (D:\PracticeJob\bs4practice\gulpfile.js:21:6)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
解决方案
这在 gulp4 中是不允许的:
gulp.task('default', ['js', 'serve', 'fa', 'fonts']);
改成:
gulp.task('default', gulp.series('js', 'serve', 'fa', 'fonts');
与此相同:
gulp.task('serve', ['sass'], function(){
改成:
gulp.task('serve', gulp.series('sass', function(){
并更改为:
gulp.watch(['node_modules/bootstrap/scss/bootstrap.scss', 'src/scss/*.scss'], 'sass');
您不能只在 gulp4 环境中使用 gulp3 代码而不进行这些更改。以上是您必须进行的最小更改,但您还需要进行更多更改才能充分利用 gulp4。参见例如gulp4 文档:创建任务。
推荐阅读
- python-3.x - 使用 OpenCV 文本检测的图像偏移校正
- node.js - 未处理的错误。(错误:无法在当前环境中检测到项目 ID
- windows - 为什么 MSYS2 的 shell 可以在文件夹 /usr/bin 中找到没有“exe”扩展名的二进制文件
- asp.net - 在单个视图中创建表单以及显示数据
- ios - iOS 上的 Web 视图
- pdf - PDF 注释/注释是否可以包含指向 PDF 中其他页面的链接?
- django - 如何按名称和最高时间戳获取对象
- c++ - 如果从函数中给定值,是否需要删除动态结构?
- rust - 将lazy_static 声明为返回 Result<> 的函数的 Ok() 结果
- reactjs - 在“/opt/app/.next”目录中找不到生产版本