简体   繁体   English

Typescript + gulp-sourcemaps生成地图,但浏览器DevTools无法识别它

[英]Typescript + gulp-sourcemaps generates map but browser DevTools don't recognize it

Using Typescript 1.8 , Gulp 3.9.0 , gulp-sourcemaps 1.6.0 , and a tsconfig.json file. 使用Typescript 1.8Gulp 3.9.0gulp-sourcemaps 1.6.0tsconfig.json文件。

At one point a long time ago this was working fine. 在很久以前的某个时候,它运行良好。 Of late (and I can't pinpoint when), neither Chrome nor Firefox will actually use the sourcemap. 最近(我无法确定确切的时间),Chrome和Firefox都不会真正使用源地图。

I've enabled sourcemaps on Chrome, and recognizes that there's a sourcemap, telling me in the console: 我已在Chrome上启用了源地图,并意识到有一个源地图,并在控制台中告诉我:

"Source Map detected. Associated files should be added to the file tree. You can debug these resolved source files as regular JavaScript files. Associated files are available via file tree or Ctrl + P." “检测到源映射。应该将相关文件添加到文件树中。您可以将这些已解析的源文件调试为常规JavaScript文件。可以通过文件树或Ctrl + P来获得相关文件。”

However, the source files are not available through either method. 但是,两种方法均无法使用源文件。

Built File Structure on local build (just using Login as an example): 在本地版本上构建文件结构(仅以登录为例):

build
  |- resources
      |- js
         |- app.js
         |- app.js.map
         |- typescript
              |- app.ts
              |- sections
                    |- login
                         |- LoginService.ts
                         |- LoginDirective.ts
                         |- LoginController.ts

However, Chrome only shows this in the file tree: 但是,Chrome仅在文件树中显示此内容:

build
  |- resources
      |- js
         |- app.js

That's it. 而已。 No Typescript folder, no files. 没有Typescript文件夹,没有文件。 Ctrl-P doesn't find them either. Ctrl-P也找不到它们。 So when I'm debugging, I can only debug the compiled app.js file rather than see the Typescript code. 因此,在调试时,我只能调试已编译的app.js文件,而不能查看Typescript代码。

My gulp file relevant sections: 我的gulp文件相关部分:

var ts = require( 'gulp-typescript' ); // compiles typescript
var tsProject = ts.createProject( 'tsconfig.json' );

gulp.task( 'compile:typescript', function () {
    var tsResult = tsProject
        .src() // instead of gulp.src(...)
        .pipe( sourcemaps.init() )
        .pipe( ts( tsProject ) );

    return tsResult.js
        .pipe( sourcemaps.write( '.', 
             {
               includeContent: false, 
               sourceRoot: 'typescript'
             }) 
         )
        .pipe( './build' )
        ;
} );

I've looked at various documentation and solutions for similar situations but I'm still not getting Chrome to use the sourcemaps. 我查看了针对类似情况的各种文档和解决方案,但我仍然没有让Chrome使用源地图。

https://www.npmjs.com/package/gulp-sourcemaps https://www.npmjs.com/package/gulp-sourcemaps

https://github.com/ivogabe/gulp-typescript/issues/201 https://github.com/ivogabe/gulp-typescript/issues/201

https://github.com/floridoo/gulp-sourcemaps/issues/89#issuecomment-73184103 https://github.com/floridoo/gulp-sourcemaps/issues/89#issuecomment-73184103

gulp-typescript: Problems using createProject ... "and much more!" gulp-typescript:使用createProject的问题 ...“还有更多!”

No idea why this isn't working correctly. 不知道为什么这不能正常工作。 Any insight, Stackers? 有见识吗,堆纸机?

In chrome dev Tools open settings (F1 in windows). 在chrome dev工具中,打开设置(在Windows中为F1)。

Make sure that options: 确保以下选项:

Sources: 资料来源:

  • Automatically reveal files in navigator 在导航器中自动显示文件
  • Enable JavaScript source maps 启用JavaScript源映射

are checked 被检查

Probably not exactly what you are looking for, I personally use webpack and source-map-loader and able to get the source map shown correctly, albeit under "webpack://" 可能不完全是您要查找的内容,我个人使用了webpacksource-map-loader并能够正确显示源地图,尽管在“ webpack://”下

图片

You can check out my configuration at https://github.com/unional/aurelia-logging-color 您可以在https://github.com/unional/aurelia-logging-color中查看我的配置

Hope it helps. 希望能帮助到你。

I believe your problem lies in how you defined the sourceRoot . 我相信您的问题在于如何定义sourceRoot Try something like sourceRoot: './typescript/' . 尝试类似sourceRoot: './typescript/'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM