尝试运行我的默认任务时,我不断收到以下错误消息:
[10:52:59] Starting 'watchFiles'...
[10:52:59] 'watchFiles' errored after 1.11 ms
[10:52:59] AssertionError [ERR_ASSERTION]: Task never defined: undefined
at getFunction (/Users/lynn/Siti/rg5/node_modules/undertaker/lib/helpers/normalizeArgs.js:15:5)
at map (/Users/lynn/Siti/rg5/node_modules/arr-map/index.js:20:14)
at normalizeArgs (/Users/lynn/Siti/rg5/node_modules/undertaker/lib/helpers/normalizeArgs.js:22:10)
at Gulp.series (/Users/lynn/Siti/rg5/node_modules/undertaker/lib/series.js:13:14)
at watchFiles (/Users/lynn/Siti/rg5/gulp/tasks/watch.js:10:10)
at bound (domain.js:395:14)
at runBound (domain.js:408:12)
at asyncRunner (/Users/lynn/Siti/rg5/node_modules/async-done/index.js:55:18)
at process._tickCallback (internal/process/next_tick.js:61:11)
[10:52:59] 'default' errored after 3.42 ms
这是我注册的任务:
[11:06:51] Tasks for ~/Siti/rg5/gulpfile.js
[11:06:51] ├─┬ default
[11:06:51] │ └─┬ <series>
[11:06:51] │ ├── watchFiles
[11:06:51] │ └── browserSync
[11:06:51] ├── browserSync
[11:06:51] ├── scripts
[11:06:51] ├── styles
[11:06:51] ├── previewDist
[11:06:51] └─┬ build
[11:06:51] └─┬ <series>
[11:06:51] ├── deleteDistFolder
[11:06:51] ├── copyGeneralFiles
[11:06:51] ├─┬ <parallel>
[11:06:51] │ ├── styles
[11:06:51] │ └── scripts
[11:06:51] ├── useMin
[11:06:51] └── optimizeImages
我的 Gulp 版本
CLI version: 2.2.0
Local version: 4.0.2
任务似乎是罪魁祸首,watchFiles
但我看不出问题出在哪里。我已经查看了所有其他报告类似错误但没有运气的 stackoverflow 结果。
这是我的gulpfile.js
const gulp = require("gulp");
const { watchFiles, browserSync } = require("./gulp/tasks/watch.js");
const scripts = require("./gulp/tasks/scripts.js");
const styles = require("./gulp/tasks/styles.js");
const {
optimizeImages,
deleteDistFolder,
useMin,
copyGeneralFiles,
previewDist
} = require("./gulp/tasks/build.js");
// Register gulp tasks
exports.default = gulp.series(watchFiles, browserSync);
exports.browserSync = browserSync;
exports.scripts = scripts;
exports.styles = styles;
exports.previewDist = previewDist;
exports.build = gulp.series(
deleteDistFolder,
copyGeneralFiles,
gulp.parallel(styles, scripts),
useMin,
optimizeImages
);
这是我的watch.js
模块,其中包括watchFiles
导致错误的任务
const gulp = require("gulp");
const browsersync = require("browser-sync").create();
const { styles } = require("./styles");
const scripts = require("./scripts");
const modernizrScript = require("./modernizr");
function watchFiles(done) {
gulp.watch(
"./app/assets/styles/sass/**/*.scss",
gulp.series(styles, cssInject, browserSyncReload)
);
gulp.watch("./app/assets/scripts/**/*.js", scripts);
gulp.watch("./app/*.html", browserSyncReload);
done();
}
function browserSyncReload(cb) {
browsersync.reload();
cb();
}
// BrowserSync
function browserSync(cb) {
browsersync.init({
server: {
baseDir: "app"
},
port: 3000
});
cb();
}
function cssInject() {
return gulp.src("./app/temp/styles/base.css").pipe(browsersync.stream());
}
module.exports = { watchFiles, browserSync };
我真的被困住了,任何帮助将不胜感激。谢谢你。