如何在上一个任务后部署 gulp-ftp?
How to deploy gulp-ftp, after previos task?
我在 npm.js 中有两个 gulp 任务有问题。第一个任务编译项目,下一个任务在 ftp 上部署它。如果我 运行 它们分开 - 所有工作,但当我尝试将它们一起使用时,它现在工作。我认为这是一个流错误。因为 gulp ftp (第二个任务)比(第一个任务)完成得更快。有人可以帮忙吗?
第一个任务:
gulp.task('build', ['nib', 'html', 'scripts'], function() {
var removeDist = del.sync('app/dist');
var buildCSS = gulp
.src('app/chache/css/*.css')
.pipe(cssnano())
.pipe(gulp.dest('app/dist/css'));
var buildImg = gulp
.src(['app/html-dev/img/**/*', '!app/html-dev/img/empty.jpg'])
.pipe(imagemin({
interlaced: true,
progressive: true,
svgoPlugins: [{ removeViewBox: false }],
une: [pngquant()]
}))
.pipe(gulp.dest('app/dist/img'));
var buildFonts = gulp
.src(["app/html-dev/fonts/**/*", '!app/html-dev/fonts/empty.woff'])
.pipe(gulp.dest('app/dist/fonts'));
var buildJS = gulp
.src("app/chache/js/**/*")
.pipe(gulp.dest('app/dist/js'));
var buildHhtml = gulp
.src("app/chache/*.html")
.pipe(gulp.dest('app/dist'));
});
Ftp 任务:
gulp.task('ftp', ['build'], function () {
return gulp.src('app/dist/**')
.pipe(ftp(ftpinfo))
// you need to have some kind of stream after gulp-ftp to make sure it's flushed
// this can be a gulp plugin, gulp.dest, or any kind of stream
// here we use a passthrough stream
.pipe(gutil.noop());
});
错误:
[13:34:47] Using gulpfile ~\Desktop\test-dist\gulpfile.js
[13:34:47] Starting 'nib'...
[13:34:47] Starting 'html'...
[13:34:47] Starting 'scripts'...
[13:34:47] Finished 'scripts' after 9.31 ms
[13:34:50] Finished 'nib' after 3.35 s
[13:34:50] Finished 'html' after 3.34 s
[13:34:50] Starting 'build'...
[13:34:50] Finished 'build' after 21 ms
[13:34:50] Starting 'ftp'...
[13:34:50] gulp-ftp: No files uploaded
[13:34:50] Finished 'ftp' after 6.5 ms
[13:34:50] gulp-imagemin: Minified 0 images
您需要 return
来自依赖任务的流,'build'
。否则父任务 'ftp'
不会等待 'build'
结束。
由于该任务有多个 src
您需要将它们与 merge-stream
合并
var merge = require('merge-stream');
gulp.task('build', ['nib', 'html', 'scripts'], function() {
var removeDist = del.sync('app/dist');
return merge(
gulp
.src('app/chache/css/*.css')
.pipe(cssnano())
.pipe(gulp.dest('app/dist/css')),
gulp
.src(['app/html-dev/img/**/*', '!app/html-dev/img/empty.jpg'])
.pipe(imagemin({
interlaced: true,
progressive: true,
svgoPlugins: [{ removeViewBox: false }],
une: [pngquant()]
}))
.pipe(gulp.dest('app/dist/img')),
gulp
.src(["app/html-dev/fonts/**/*", '!app/html-dev/fonts/empty.woff'])
.pipe(gulp.dest('app/dist/fonts')),
gulp
.src("app/chache/js/**/*")
.pipe(gulp.dest('app/dist/js')),
gulp
.src("app/chache/*.html")
.pipe(gulp.dest('app/dist'))
);
});
我在 npm.js 中有两个 gulp 任务有问题。第一个任务编译项目,下一个任务在 ftp 上部署它。如果我 运行 它们分开 - 所有工作,但当我尝试将它们一起使用时,它现在工作。我认为这是一个流错误。因为 gulp ftp (第二个任务)比(第一个任务)完成得更快。有人可以帮忙吗?
第一个任务:
gulp.task('build', ['nib', 'html', 'scripts'], function() {
var removeDist = del.sync('app/dist');
var buildCSS = gulp
.src('app/chache/css/*.css')
.pipe(cssnano())
.pipe(gulp.dest('app/dist/css'));
var buildImg = gulp
.src(['app/html-dev/img/**/*', '!app/html-dev/img/empty.jpg'])
.pipe(imagemin({
interlaced: true,
progressive: true,
svgoPlugins: [{ removeViewBox: false }],
une: [pngquant()]
}))
.pipe(gulp.dest('app/dist/img'));
var buildFonts = gulp
.src(["app/html-dev/fonts/**/*", '!app/html-dev/fonts/empty.woff'])
.pipe(gulp.dest('app/dist/fonts'));
var buildJS = gulp
.src("app/chache/js/**/*")
.pipe(gulp.dest('app/dist/js'));
var buildHhtml = gulp
.src("app/chache/*.html")
.pipe(gulp.dest('app/dist'));
});
Ftp 任务:
gulp.task('ftp', ['build'], function () {
return gulp.src('app/dist/**')
.pipe(ftp(ftpinfo))
// you need to have some kind of stream after gulp-ftp to make sure it's flushed
// this can be a gulp plugin, gulp.dest, or any kind of stream
// here we use a passthrough stream
.pipe(gutil.noop());
});
错误:
[13:34:47] Using gulpfile ~\Desktop\test-dist\gulpfile.js
[13:34:47] Starting 'nib'...
[13:34:47] Starting 'html'...
[13:34:47] Starting 'scripts'...
[13:34:47] Finished 'scripts' after 9.31 ms
[13:34:50] Finished 'nib' after 3.35 s
[13:34:50] Finished 'html' after 3.34 s
[13:34:50] Starting 'build'...
[13:34:50] Finished 'build' after 21 ms
[13:34:50] Starting 'ftp'...
[13:34:50] gulp-ftp: No files uploaded
[13:34:50] Finished 'ftp' after 6.5 ms
[13:34:50] gulp-imagemin: Minified 0 images
您需要 return
来自依赖任务的流,'build'
。否则父任务 'ftp'
不会等待 'build'
结束。
由于该任务有多个 src
您需要将它们与 merge-stream
var merge = require('merge-stream');
gulp.task('build', ['nib', 'html', 'scripts'], function() {
var removeDist = del.sync('app/dist');
return merge(
gulp
.src('app/chache/css/*.css')
.pipe(cssnano())
.pipe(gulp.dest('app/dist/css')),
gulp
.src(['app/html-dev/img/**/*', '!app/html-dev/img/empty.jpg'])
.pipe(imagemin({
interlaced: true,
progressive: true,
svgoPlugins: [{ removeViewBox: false }],
une: [pngquant()]
}))
.pipe(gulp.dest('app/dist/img')),
gulp
.src(["app/html-dev/fonts/**/*", '!app/html-dev/fonts/empty.woff'])
.pipe(gulp.dest('app/dist/fonts')),
gulp
.src("app/chache/js/**/*")
.pipe(gulp.dest('app/dist/js')),
gulp
.src("app/chache/*.html")
.pipe(gulp.dest('app/dist'))
);
});