0

我正在使用一些 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'));

});

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

4

1 回答 1

1

gulp-if与 结合使用仅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'));
});
于 2016-07-14T10:55:33.140 回答