Gulpfile没有将文件从源移动到目标

时间:2016-05-11 10:24:26

标签: visual-studio-2015 angular gulp task-runner-explorer

我在 Visual Studio 2015 项目中创建了gulpfile.js。它被设置为afterbuild。当我编译项目时,我在 Task Runner Explorer 中看到以下消息。以下是gulp文件的源代码

任务运行器中的错误消息

cmd.exe /c gulp -b "C:\Tom\Personal\PracticeProjects\Angular2\AspNet5Angular2Demo\src\AspNet5Angular2Demo" --color --gulpfile "C:\Tom\Personal\PracticeProjects\Angular2\AspNet5Angular2Demo\src\AspNet5Angular2Demo\Gulpfile.js" default
[12:06:26] 
Process terminated with code 1

Gulp文件

   var gulp = require('gulp');    
gulp.task('moveToLibs', function (done) {
     gulp.src([
      'node_modules/angular2/bundles/js',
      'node_modules/angular2/bundles/angular2.*.js*',
      'node_modules/angular2/bundles/angular2-polyfills.js',
      'node_modules/angular2/bundles/http.*.js*',
      'node_modules/angular2/bundles/router.*.js*',
      'node_modules/es6-shim/es6-shim.min.js*',
      'node_modules/angular2/es6/dev/src/testing/shims_for_IE.js',
      'node_modules/systemjs/dist/*.*',
      'node_modules/jquery/dist/jquery.*js',
      'node_modules/bootstrap/dist/js/bootstrap*.js',
      'node_modules/rxjs/bundles/Rx.js'
    ]).pipe(gulp.dest('./wwwroot/libs/'));

     gulp.src([
      'node_modules/bootstrap/dist/css/bootstrap.css'
    ]).pipe(gulp.dest('./wwwroot/libs/css'));
});

我已经修改了上面的代码如下,但仍然得到相同的错误。我安装了merge2,并在devDependencies文件的package.json下提及。

的package.json

{
  "version": "0.0.0",
  "name": "Angular2AspNetCoreDemo",
  "dependencies": {
    "angular2": "2.0.0-beta.17",
    "systemjs": "0.19.27",
    "es6-promise": "^3.1.2",
    "es6-shim": "^0.35.0",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.6",
    "zone.js": "0.6.12",
    "bootstrap": "^3.3.6",
    "jquery": "^2.2.3"

  },
  "devDependencies": {
    "gulp": "^3.9.1",
    "merge2": "1.0.2"
  }
}

gulpfile.js

  /// <binding AfterBuild='default' />
    var gulp = require('gulp');
    var merge2 = require('merge2');        

    gulp.task('moveToLibs', function (done) {
        return merge2
        (
        gulp.src([
          'node_modules/angular2/bundles/js',
          'node_modules/angular2/bundles/angular2.*.js*',
          'node_modules/angular2/bundles/angular2-polyfills.js',
          'node_modules/angular2/bundles/http.*.js*',
          'node_modules/angular2/bundles/router.*.js*',
          'node_modules/es6-shim/es6-shim.min.js*',
          'node_modules/angular2/es6/dev/src/testing/shims_for_IE.js',
          'node_modules/systemjs/dist/*.*',
          'node_modules/jquery/dist/jquery.*js',
          'node_modules/bootstrap/dist/js/bootstrap*.js',
          'node_modules/rxjs/bundles/Rx.js'
        ]).pipe(gulp.dest('./wwwroot/libs/')),

         gulp.src([
          'node_modules/bootstrap/dist/css/bootstrap.css'
        ]).pipe(gulp.dest('./wwwroot/libs/css')))

    });

我也试过把它作为我的gulp文件中的两个单独的任务,仍然得到同样的错误

/// <binding AfterBuild='default' />
var gulp = require('gulp');


gulp.task('moveToLibs', function (done) {
    gulp.src([
      'node_modules/angular2/bundles/js',
      'node_modules/angular2/bundles/angular2.*.js*',
      'node_modules/angular2/bundles/angular2-polyfills.js',
      'node_modules/angular2/bundles/http.*.js*',
      'node_modules/angular2/bundles/router.*.js*',
      'node_modules/es6-shim/es6-shim.min.js*',
      'node_modules/angular2/es6/dev/src/testing/shims_for_IE.js',
      'node_modules/systemjs/dist/*.*',
      'node_modules/jquery/dist/jquery.*js',
      'node_modules/bootstrap/dist/js/bootstrap*.js',
      'node_modules/rxjs/bundles/Rx.js'
    ]).pipe(gulp.dest('./wwwroot/libs/'))
});
gulp.task('moveToLibsCss', function (done) {

     gulp.src([
      'node_modules/bootstrap/dist/css/bootstrap.css'
    ]).pipe(gulp.dest('./wwwroot/libs/css'))

});

2 个答案:

答案 0 :(得分:0)

我认为您需要将任务名称更改为default,如

gulp.task('moveToLibs', function (done) {...}

或添加一个空的默认任务,并使其依赖于您的moveToLibs

gulp.task('default',['moveToLibs']);

答案 1 :(得分:0)

我认为错误的glob模式可能是问题的一部分,你有:

gulp.task('moveToLibs', function (done) {
    gulp.src([
      'node_modules/angular2/bundles/js',
      'node_modules/angular2/bundles/angular2.*.js*',
      'node_modules/angular2/bundles/angular2-polyfills.js',
      'node_modules/angular2/bundles/http.*.js*',
      'node_modules/angular2/bundles/router.*.js*',
      'node_modules/es6-shim/es6-shim.min.js*',
      'node_modules/angular2/es6/dev/src/testing/shims_for_IE.js',
      'node_modules/systemjs/dist/*.*',
      'node_modules/jquery/dist/jquery.*js',
      'node_modules/bootstrap/dist/js/bootstrap*.js',
      'node_modules/rxjs/bundles/Rx.js'
    ]).pipe(gulp.dest('./wwwroot/libs/'))
});

而是试试这个:

gulp.task('moveToLibs', function (done) {
    gulp.src([
      // 'node_modules/angular2/bundles/js', // folder doesn't exist
      'node_modules/angular2/bundles/angular2.*.js',
      'node_modules/angular2/bundles/angular2-polyfills.js',
      'node_modules/angular2/bundles/http.*.js',
      'node_modules/angular2/bundles/router.*.js',
      'node_modules/es6-shim/es6-shim.min.js',
      'node_modules/angular2/es6/dev/src/testing/shims_for_IE.js',
      'node_modules/systemjs/dist/*.*',
      'node_modules/jquery/dist/jquery.js',
      'node_modules/bootstrap/dist/js/bootstrap.js',
      'node_modules/rxjs/bundles/Rx.js'
    ]).pipe(gulp.dest('./wwwroot/libs/'))
});

请注意差异,它们很小但很可能是导致问题的原因。使用 Angular2 ASP.NET Core 一起查看my post,我详细介绍了从node_modules提取的示例gulp文件。

<强>更新

devDependency上添加gulp-debug并添加:

var debug = require("gulp-debug");

然后将其添加到您的流中以调试文件,以确保您获得所期望的内容:

gulp.task('moveToLibs', function (done) {
    gulp.src([
      // 'node_modules/angular2/bundles/js', // folder doesn't exist
      'node_modules/angular2/bundles/angular2.*.js',
      'node_modules/angular2/bundles/angular2-polyfills.js',
      'node_modules/angular2/bundles/http.*.js',
      'node_modules/angular2/bundles/router.*.js',
      'node_modules/es6-shim/es6-shim.min.js',
      'node_modules/angular2/es6/dev/src/testing/shims_for_IE.js',
      'node_modules/systemjs/dist/*.*',
      'node_modules/jquery/dist/jquery.js',
      'node_modules/bootstrap/dist/js/bootstrap.js',
      'node_modules/rxjs/bundles/Rx.js'
    ])
    .pipe(debug())
    .pipe(gulp.dest('./wwwroot/libs/'))
});