我必须将旧项目从gulp版本3.9.1升级到gulp版本4,这需要我重写任务。我已经按照文档中的说明移至gulp.series和名称函数,但现在运行中仍然出现错误。下面是我的代码,用于观看两种不同语言的样式。
var fontName = "project-icons",
gulp = require("gulp"),
sass = require("gulp-sass"),
sourcemaps = require("gulp-sourcemaps"),
iconfont = require("gulp-iconfont"),
iconfontCss = require("gulp-iconfont-css");
var sassOptions = {
errLogToConsole: true,
outputStyle: "expanded"
};
function iconfont(done) {
gulp.src(["./icons/*.svg"])
.pipe(
iconfontCss({
fontName: fontName,
path: "sass",
targetPath: "../sass/static/icons/_icons.sass",
fontPath: "./fonts/",
cssClass: "icon"
})
)
.pipe(
iconfont({
formats: ["ttf", "eot", "woff", "woff2", "svg"],
fontName: fontName,
normalize: true,
fixedWidth: true,
centerHorizontally: true
})
)
.on("glyphs", function(glyphs, options) {})
.pipe(gulp.dest("./fonts/"));
done();
}
function desktop_styles() {
return gulp
.src("./sass/_en/style.sass")
.pipe(
sourcemaps.init({
loadMaps: true,
identityMap: true,
sourceRoot: "../css/"
})
)
.pipe(sass(sassOptions).on("error", sass.logError))
.pipe(sourcemaps.write())
.pipe(gulp.dest("./css/"));
}
function desktop_styles_rtl() {
return gulp
.src("./sass/_ar/style.sass")
.pipe(
sourcemaps.init({
loadMaps: true,
identityMap: true,
sourceRoot: "../css/"
})
)
.pipe(sass(sassOptions).on("error", sass.logError))
.pipe(sourcemaps.write())
.pipe(gulp.dest("./css/lang/rtl"));
}
function mobile_styles() {
return gulp
.src("./sass/en/mobile/style.sass")
.pipe(sass(sassOptions).on("error", sass.logError))
.pipe(gulp.dest("./css/m"));
}
function mobile_styles_rtl() {
return gulp
.src("./sass/rtl/m/style.sass")
.pipe(sass(sassOptions).on("error", sass.logError))
.pipe(gulp.dest("./css/lang/rtl/m"));
}
function watch_all(){
gulp.series(
mobile_styles,
mobile_styles_rtl,
desktop_styles,
desktop_styles_rtl,
function(done) {
gulp.watch("./sass/**/*.sass", gulp.series(mobile_styles));
gulp.watch("./sass/**/*.sass", gulp.series(mobile_styles_rtl));
gulp.watch("./sass/**/*.sass", gulp.series(desktop_styles));
gulp.watch("./sass/**/*.sass", gulp.series(desktop_styles_rtl));
done();
}
)
};
function watch_AllDesktop(done){
gulp.series(desktop_styles, desktop_styles_rtl, function() {
gulp.watch("./sass/**/*.sass", gulp.series(desktop_styles));
gulp.watch("./sass/**/*.sass", gulp.series(desktop_styles_rtl));
done();
});
function watch_desk_desktop_styles_rtl(done){
gulp.series(desktop_styles_rtl, function() {
gulp.watch("./sass/**/*.sass", gulp.series(desktop_styles_rtl));
done();
});
function watch_desktop_en(done){
gulp.series(desktop_styles, function() {
gulp.watch("./sass/**/*.sass", gulp.series(desktop_styles));
});
function watch_mobile_rtl(done){
gulp.series(mobile_styles_rtl, function() {
gulp.watch("./sass/**/*.sass", gulp.series(mobile_styles_rtl));
done();
});
function watch_mobile_en(done){
gulp.series(mobile_styles, function() {
gulp.watch("./sass/**/*.sass", gulp.series(mobile_styles));
done();
});
function watch_AllMobile(done){
gulp.series(mobile_styles, mobile_styles_rtl, function() {
gulp.watch("./sass/**/*.sass", gulp.series(mobile_styles));
gulp.watch("./sass/**/*.sass", gulp.series(mobile_styles_rtl));
done();
});
当我运行“ gulp watch_all”时,得到的任务从未定义。函数或我的代码顺序有问题吗?
答案 0 :(得分:1)
从watch_AllDesktop
到watch_AllMobile
的所有功能都需要用右括号}
您的主要问题是,您不导出任务
实习生任务无需导出,但是所有应在每个控制台上运行的任务都必须导出。
例如,在gulpfile.js的末尾导出后放置:
exports.watch_all = watch_all;
导出后,您可以使用gulp --tasks
证明哪些任务适合您
编辑(评论问题)
您的手表应该没有回调,因为该手表应该永久运行,而不仅仅是运行一次。
function watch_all(){
gulp.watch("./sass/**/*.sass", gulp.series(mobile_styles, mobile_styles_rtl, desktop_styles, desktop_styles_rtl ));
}
有关其他问题,请用小示例和受影响的代码打开新问题。