我不得不将一个旧项目从 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”时,我得到任务从未定义。功能或我的代码顺序有问题吗?