最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Gulp and FTP : How to transfer only the content of a folder? - Stack Overflow

programmeradmin4浏览0评论

Gulp with vinyl ftp : how to specify different directory name? I am using vinyl-ftp with gulp to push my local dist/ directory to remote production server.

Thing is my local ready-to-production directory name is "dist", and I want all of its content to be pushed in a "www" directory on the server.

The code is :

gulp.task( 'deploy:prod', ['build:dist'], function() {

    var conn = ftp.create( {
        host:     'ftp.website',
        user:     'username',
        password: 'password'
    } );

    var globs = ['./dist/**'];

    return gulp.src( globs, {base: '.', buffer: false } )
        .pipe( conn.differentSize( 'www/' ) ) 
        .pipe( conn.dest( 'www/' ) );
} );

As you see, I'm trying to get only the content of dist/ by targeting './dist/**', but after transfer is done, the path I get is : /www/dist/.

One workaround would be to rename my "dist/" folder to "www/" and then set vinyl ftp's destination to server ROOT, but I'd prefer to keep concerns separated and keep the name "dist/" for my local build.

Do you have any ideas on how to have the content of my local dist/ folder transferred into the remote www/ folder ?

Gulp with vinyl ftp : how to specify different directory name? I am using vinyl-ftp with gulp to push my local dist/ directory to remote production server.

Thing is my local ready-to-production directory name is "dist", and I want all of its content to be pushed in a "www" directory on the server.

The code is :

gulp.task( 'deploy:prod', ['build:dist'], function() {

    var conn = ftp.create( {
        host:     'ftp.website.',
        user:     'username',
        password: 'password'
    } );

    var globs = ['./dist/**'];

    return gulp.src( globs, {base: '.', buffer: false } )
        .pipe( conn.differentSize( 'www/' ) ) 
        .pipe( conn.dest( 'www/' ) );
} );

As you see, I'm trying to get only the content of dist/ by targeting './dist/**', but after transfer is done, the path I get is : /www/dist/.

One workaround would be to rename my "dist/" folder to "www/" and then set vinyl ftp's destination to server ROOT, but I'd prefer to keep concerns separated and keep the name "dist/" for my local build.

Do you have any ideas on how to have the content of my local dist/ folder transferred into the remote www/ folder ?

Share Improve this question edited Mar 26, 2015 at 1:33 cimmanon 68.4k17 gold badges168 silver badges172 bronze badges asked Mar 26, 2015 at 1:16 lapinlapin 2,1483 gold badges22 silver badges32 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 9

Try to set your base to ./dist/:

return gulp.src( globs, {base: './dist/', buffer: false } )
    .pipe( conn.differentSize( 'www/' ) ) 
    .pipe( conn.dest( 'www/' ) );

According to the API documentation and some blurred memories this flag's for exactly that case.

发布评论

评论列表(0)

  1. 暂无评论