【发布时间】:2019-04-19 04:22:39
【问题描述】:
我正在学习 GULP,我希望页面在我修改 CSS 时自动更新。
const gulp = require("gulp");
const jshint = require("gulp-jshint");
const changed = require("gulp-changed");
const watch = require("gulp-watch");
const rename = require("gulp-rename");
const minifyCSS = require("gulp-uglifycss");
const sass = require("gulp-sass");
const cssImport = require("gulp-cssimport");
gulp.task("changed", function() {
return gulp
.src("src/css/*.css")
.pipe(changed("public/assets/css/"))
.pipe(cssImport())
.pipe(sass())
.pipe(minifyCSS())
.pipe(rename({ extname: ".min.css" }))
.pipe(gulp.dest("public/assets/css/"));
});
gulp.task("jshint", function() {
gulp
.src("src/css/*.css")
.pipe(jshint())
.pipe(jshint.reporter("default"));
});
gulp.task("watch", function() {
watch("src/css/*.css", ["changed"]);
});
gulp.task("default", ["jshint", "watch"]);
我正在尝试使用 "gulp-watch",但它给出了错误 "Task function must be specified" 在上面的这段代码中。
【问题讨论】:
-
任务的名称是“watch”,所以尝试使用它,而不是“gulp-watch”。
-
但是我已经使用了任务'watch',看看我的默认任务
-
当你有一个名为“default”的任务时,你甚至不需要使用这个名字。您只需使用 "gulp" 运行默认任务。关于“观看”任务,@slotomo 是对的。您只需运行“gulp watch”而不是“gulp-watch”。
标签: gulp gulp-watch