Gulp:不针对.service.ts文件

时间:2018-02-15 12:00:35

标签: angular typescript gulp gulp-concat gulp-sourcemaps

我遇到了一个问题,当我为我的gulpfile运行我的任务运行器时,除了似乎错过的resource.service.ts之外,它正确地定位了我的所有.ts文件。

下面显示了gulp脚本接受和定位的文件:

  • main.ts
  • resource.ts
  • 资源list.component.ts
  • test.component.ts
  • test.module.ts

引用此.service.ts文件引用的特定任务是应用程序任务。

以下是我的gulp脚本:

//References to required plugins
var gulp = require("gulp"),
    gp_clean = require('gulp-clean'),
    gp_concat = require('gulp-concat'),
    gp_sourcemaps = require('gulp-sourcemaps'),
    gp_typescript = require('gulp-typescript'),
    gp_uglify = require('gulp-uglify'),
    gp_typescript_config = require('gulp-ts-config');

//Define source paths
var srcPaths = {
    app: ['app/main.ts', 'app/**/*.ts'],
    js: ['js/**/*.js',
        'node_modules/core-js/client/shim.min.js',
        'node_modules/zone.js/dist/zone.js',
        'node_modules/reflect-metadata/Reflect.js',
        'node_modules/systemjs/dist/system.src.js',
        'node_modules/typescript/lib/typescript.js']
    , js_angular: ['node_modules/@angular/**']
    , js_rxjs: ['node_modules/rxjs/**']
};

//Define destination paths
var destPaths = {
    app: 'wwwroot/app/',
    app_local: 'app/',
    js: 'wwwroot/js/',
    js_angular: 'wwwroot/js/@angular/',
    js_rxjs: 'wwwroot/js/rxjs/' 
};

//Compile, minifiy, and create sourcemaps for typescipt files and place them in wwwroot/app, together with the js.map files
gulp.task('app', function() {
    return gulp.src(srcPaths.app)
        .pipe(gp_sourcemaps.init())
        .pipe(gp_typescript(require('./tsconfig.json').compilerOptions))
        .pipe(gp_uglify({ mangle: false }))
        .pipe(gp_sourcemaps.write('/'))
        .pipe(gulp.dest(destPaths.app));
});

//Delete contents of wwwroot/app
gulp.task('app-clean', function () {
    return gulp.src(destPaths.app + "*", { read: false })
        .pipe(gp_clean({ force: true }));
});

//Copy js files from external libs to wwwroot/js
gulp.task('js', function () {
    gulp.src(srcPaths.js_angular)
        .pipe(gulp.dest(destPaths.js_angular));
    gulp.src(srcPaths.js_rxjs)
        .pipe(gulp.dest(destPaths.js_rxjs));

    return gulp.src(srcPaths.js)
        .pipe(gulp.dest(destPaths.js));
});

//Delete contents of wwwroot/js
gulp.task('js-clean', function () {
    return gulp.src(destPaths.js + "*", { read: false })
        .pipe(gp_clean({force: true }));
});


//Watch files and act on change
gulp.task('watch', function () {
    gulp.watch([srcPaths.app, srcPaths.js], ['app', 'js']);
});

//Global clean
gulp.task('cleanup', ['app-clean', 'js-clean']);

//Default task
gulp.task('default', ['app', 'js', 'watch']);

供参考,这是在Visual Studio 2017中

1 个答案:

答案 0 :(得分:0)

我发现了解决方案。似乎gulp对我有两个名为resource(resource.ts和resource.service.ts)的.ts文件的事实并不满意。通过将resource.service.ts更改为resourceservice.service.ts,我能够像项目中的其他文件一样正确地将文件定位到gulp中。