Gulp不生成内联源图

时间:2016-09-14 19:59:45

标签: visual-studio typescript gulp

我在ASP.NET Core中有以下tsconfig.json文件:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "inlineSourceMap": true,
    "inlineSources": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noEmitOnError": false,
    "noImplicitAny": false,
    "removeComments": false,
    "outDir": "wwwroot/client-app"
},
  "exclude": [
    "node_modules",
    "wwwroot",
    "typings"
  ]
}

当我通过Visual Studio构建项目时,生成的js文件在文件末尾有内联源映射:

/// <reference path="../typings/index.d.ts" />
"use strict";
var platform_browser_dynamic_1 = require('@angular/platform-browser-dynamic');
var client_application_module_1 = require('./client-application.module');
platform_browser_dynamic_1.platformBrowserDynamic().bootstrapModule(client_application_module_1.ClientApplicationModule);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYm9vdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL0NsaWVudEFwcC9ib290LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDhDQUE4Qzs7QUFFOUMseUNBQXVDLG1DQUFtQyxDQUFDLENBQUE7QUFDM0UsMENBQXdDLDZCQUE2QixDQUFDLENBQUE7QUFFdEUsaURBQXNCLEVBQUUsQ0FBQyxlQUFlLENBQUMsbURBQXVCLENBQUMsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCIuLi90eXBpbmdzL2luZGV4LmQudHNcIiAvPlxyXG5cclxuaW1wb3J0IHsgcGxhdGZvcm1Ccm93c2VyRHluYW1pYyB9IGZyb20gJ0Bhbmd1bGFyL3BsYXRmb3JtLWJyb3dzZXItZHluYW1pYyc7XHJcbmltcG9ydCB7IENsaWVudEFwcGxpY2F0aW9uTW9kdWxlIH0gZnJvbSAnLi9jbGllbnQtYXBwbGljYXRpb24ubW9kdWxlJztcclxuXHJcbnBsYXRmb3JtQnJvd3NlckR5bmFtaWMoKS5ib290c3RyYXBNb2R1bGUoQ2xpZW50QXBwbGljYXRpb25Nb2R1bGUpOyJdfQ==

但是当我用Gulp构建js文件时,没有生成内联源图,就像它忽略了tsconfig.json

一样

以下是将TypeScript转换为JavaScript的Gulp任务:

    var tsProject = ts.createProject('tsconfig.json');

    gulp.task('transpile', function ()
    {
        var tsResult = gulp.src(["ClientApp/**/*.ts"])
            .pipe(ts(tsProject), undefined, ts.reporter.fullReporter()).js
            .pipe(gulp.dest('./wwwroot/client-app'));
    });

我是否需要在Gulp中进行任何额外配置,以便生成内联源图?

我正在使用TypeScript 1.8.10

1 个答案:

答案 0 :(得分:1)

我从未设法使用简单的打字稿gulp任务,我总是使用gulp-sourcemaps插件来执行此操作。

通常是这样的:

var sourcemaps = require('gulp-sourcemaps');
var typescript = require('gulp-typescript');

gulp.task('typescript', function () {
    gulp.src(["ClientApp/**/*.ts"])
        .pipe(sourcemaps.init())
        .pipe(typescript())
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('./wwwroot/client-app'))    
});