2

gulpfile.jsVisual Studio 2015项目中创建了一个。它已设置为后构建。当我编译我的项目时,我在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

吞咽文件

   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下也提到了。devDependenciespackage.json

包.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'))

});
4

2 回答 2

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

请注意差异,它们很小,但它们很可能是问题的原因。看看关于将Angular2ASP.NET Core结合使用的帖子,我详细介绍了一个示例 gulp 文件,该文件从node_modules.

更新

添加一个devDependencygulp-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/'))
});
于 2016-05-11T11:19:42.670 回答
0

我认为您需要将任务的名称更改为default喜欢

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

或添加一个空的默认任务并使其取决于您的moveToLibs喜好:

gulp.task('default',['moveToLibs']);
于 2016-05-11T11:15:38.913 回答