3

我是 Gulp 构建工具的新手。我最近开始在我的项目中使用 Gulp。我正确地完成了以下操作,压缩、压缩、jsx 文件到 js 文件。但我的要求是将我的构建文件夹发送到位于的远程服务器另一个地方。为此,我使用 gulp-scp npm 将文件夹复制到远程服务器,但它没有将文件夹复制到服务器。下面的代码是 gulpfile.js

var gulp   = require('gulp'),
    scp    = require('gulp-scp2');
gulp.task('default', function() {
  return gulp.src('src/*.js')
  .pipe(scp({
    host: '192.50.10.31',
    username: 'applmgr',
    password:'123456',
    dest: '/Data/project'
  }))
  .on('error', function(err) {
    console.log(err);
  });
});

在此代码中,我将所有 js 文件项目复制到远程服务器的 Data 文件夹中。我运行我的 gulpfile,js

c:\gulpproject>gulp

[10:19:36] 使用 gulpfile c:\gulpproject\gulpfile.js

[10:19:36] 开始“默认”...

像这样出现并且没有显示任何内容可以帮助我为什么会这样以及我的代码在哪里出错

4

2 回答 2

4

好的,我使用 gulp-rsync npm 插件解决了这个问题。但是在 Windows 中,您需要将文件从本地复制到远程系统,因为您的系统支持 rsync 并且还包含 ssh 命令。我在 Linux 中尝试了这个并安装了 rsync。

var gulp = require('gulp');
var uglify = require('gulp-uglify');
var react = require('gulp-react');
var rsync = require('gulp-rsync');


gulp.task('scripts', function() {
  // Minify and copy all JavaScript (except vendor scripts) 
  // with sourcemaps all the way down 
  return gulp.src("src/*.jsx")
    .pipe(react())
    .pipe(uglify())
    .pipe(gulp.dest('build/js'));
});
gulp.task('deploy',['scripts'], function() {
  gulp.src('build/**')
    .pipe(rsync({
      root: 'build',
      hostname: 'ramprasad@10.60.48.11',
      destination: '/Data/rrv'
    }));
 gulp.src('build/**')
    .pipe(rsync({
      root: 'build',
      hostname: 'appl@10.30.10.42',
      destination: '/Data/rrv'
    }));
   });


// The default task (called when you run `gulp` from cli) 
gulp.task('default', ['deploy']);
于 2015-05-04T07:09:22.090 回答
0

您可以使用powershellcmdbatch

var spawn = require("child_process").spawn,child;
child = spawn("powershell.exe",["c:\\temp\\helloworld.ps1"]);
child.stdout.on("data",function(data){
    console.log("Powershell Data: " + data);
});
child.stderr.on("data",function(data){
    console.log("Powershell Errors: " + data);
});
child.on("exit",function(){
    console.log("Powershell Script finished");
});
child.stdin.end(); //end input
于 2019-12-22T11:01:55.983 回答