Gulp 将 ftp 部署到生产环境

Gulp deploy ftp to production

我正在使用一些 gulp 任务来部署到生产环境,但是我在 gulp-deploy 方面遇到问题,我需要从其他文件夹中复制一些其他文件到服务器上的不同位置是我的任务

//Gulp APP ftp deploy
gulp.task('deploy-app', function () {

    var conn = ftp.create({
        host: 'xxx',
        user: 'xxx',
        password: 'xxx',
        parallel: 10,
        log: gutil.log
    });

    var globs = [
        './css/**/*{css,png,jpg,gif,ttf,woff,eof,svg,woff2}',
        './img/**',
        './views/**',
        './scripts/**',
        'index.html',
        'Web.config'
    ];

    // 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('/site/wwwroot')) // only upload newer files 
        .pipe(conn.dest('/site/wwwroot'));

});

我这里的问题是我不需要来自 root 的 index.html,因为我还有另一个 index.html 位于文件夹 dist 中,但它必须位于服务器文件夹的根目录中,如何做到这一点

使用 gulp-if in combination with gulp-rename 仅更改 index.html 文件的目标目录而不影响任何其他文件:

var gulpIf = require('gulp-if');
var rename = require('gulp-rename');

gulp.task('deploy-app', function () {

    var conn = ftp.create({
        host: 'xxx',
        user: 'xxx',
        password: 'xxx',
        parallel: 10,
        log: gutil.log
    });

    var globs = [
        './css/**/*{css,png,jpg,gif,ttf,woff,eof,svg,woff2}',
        './img/**',
        './views/**',
        './scripts/**',
        './dist/index.html',
        'Web.config'
    ];

    return gulp.src(globs, { base: '.', buffer: false })
        .pipe(gulpIf('dist/index.html', rename({dirname:''})))
        .pipe(conn.newer('/site/wwwroot')) 
        .pipe(conn.dest('/site/wwwroot'));
});