【问题标题】:Using gulp-sftp to upload only changed files使用 gulp-sftp 仅上传更改的文件
【发布时间】:2014-08-03 02:23:59
【问题描述】:

我在 gulp 中有以下任务:

gulp.task('sync-frontend', /*['build-frontend'],*/ function()
{

    if(config.layout.frontend.syncOnBuild)
        return gulp
            .src(config.layout.frontend.distDir + '/**')
            .pipe(changed(config.layout.frontend.distDir, {hasChanged: changed.compareSha1Digest}))
            //.pipe(debug())
            .pipe(gulp.dest(config.layout.frontend.distDir))
            .pipe(sftp
            ({

                host: config.sftp.host,
                port: config.sftp.port,
                user: config.sftp.user,
                pass: config.sftp.pass,
                remotePath: (config.layout.frontend.remotePath ? config.layout.frontend.remotePath : config.sftp.remotePath )

            }));

});

config.layout.frontend.distDir 值为 'httpdocs'。

问题是没有文件被上传,无论它们是否被更改(我已经尝试将 gulp-changed 的​​ hasChange 选项保留为默认值。我总是得到以下输出:

[20:45:52] Using gulpfile /Storage/Portable/Sync/Projects/Prataria/web-prataria/gulpfile.js
[20:45:52] Starting 'sync-frontend'...
[20:45:52] gulp-sftp: No files uploaded
[20:45:52] Finished 'sync-frontend' after 503 ms

有什么想法吗?

【问题讨论】:

    标签: node.js sftp gulp gulp-watch


    【解决方案1】:

    我遇到了这个问题,发现 gulp.src 上的格式需要以 ./ 为前缀才能找到正确的文件夹。所以尝试将./httpdocs 作为config.layout.frontend.distDir 的值。

    【讨论】:

      【解决方案2】:

      您可以将 gulp-sftp 与“gulp-changed”或“gulp-watch”等其他库一起使用。

      【讨论】:

        【解决方案3】:

        尝试使用vinyl-ftp 库。 newer 功能可用于仅上传较新的文件。该库的 README 甚至包括一个示例 Gulp 任务,它显示了这一点:

        var gulp = require( 'gulp' );
        var gutil = require( 'gulp-util' );
        var ftp = require( 'vinyl-ftp' );
        
        gulp.task( 'deploy', function () {
        
            var conn = ftp.create( {
                host:     'mywebsite.tld',
                user:     'me',
                password: 'mypass',
                parallel: 10,
                log:      gutil.log
            } );
        
            var globs = [
                'src/**',
                'css/**',
                'js/**',
                'fonts/**',
                'index.html'
            ];
        
            // using base = '.' will transfer everything to /public_html correctly
            // turn off buffering in gulp.src for best performance
        
            return gulp.src( globs, { base: '.', buffer: false } )
                .pipe( conn.newer( '/public_html' ) ) // only upload newer files
                .pipe( conn.dest( '/public_html' ) );
        
        } );
        

        【讨论】:

        • VinylFTP 非常好,除非您需要通过 SFTP(端口 22)上传,而 VinylFTP 无法处理。
        猜你喜欢
        • 1970-01-01
        • 2017-03-11
        • 2012-03-23
        • 1970-01-01
        • 2019-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多