【问题标题】:Gulp deploy ftp to productionGulp 将 ftp 部署到生产环境
【发布时间】:2016-07-14 09:50:26
【问题描述】:

我正在使用一些 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 strong> 但它必须在服务器文件夹的根目录下,如何做到这一点

【问题讨论】:

    标签: javascript gulp gulp-ftp vinyl-ftp


    【解决方案1】:

    gulp-ifgulp-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'));
    });
    

    【讨论】:

      猜你喜欢
      • 2012-08-03
      • 1970-01-01
      • 2013-10-15
      • 2016-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多