加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

typescript – 浏览中ts文件的空内容

发布时间:2020-12-16 03:43:17 所属栏目:asp.Net 来源:网络整理
导读:我在ASP.NET-Core中创建了一个项目.该项目已配置,对于文件夹wwwroot仅包含* .html,* .css,* .js等本地文件.扩展名为* .ts的文件位于其他文件夹名称脚本中.一切看起来像: tsconfig.json的设置: { "compilerOptions": { "emitDecoratorMetadata": true,"expe
我在ASP.NET-Core中创建了一个项目.该项目已配置,对于文件夹wwwroot仅包含* .html,* .css,* .js等本地文件.扩展名为* .ts的文件位于其他文件夹名称脚本中.一切看起来像:

enter image description here

tsconfig.json的设置:

{
  "compilerOptions": {
    "emitDecoratorMetadata": true,"experimentalDecorators": true,"module": "commonjs","noEmitOnError": true,"noImplicitAny": false,"outDir": "../wwwroot/appScripts/","removeComments": false,"sourceMap": true,"target": "es5"
  },"exclude": [
    "node_modules"    
  ]
}

一切都很好编译.如您所见:属性sourceMap(在tsconfig.json中)的值为true,并且在每个* .js(由..ts *创建)的末尾添加了sourceMapping:

enter image description here

app.js.map:

{
  "version": 3,"file": "app.js","sourceRoot": "","sources": [
    "../../scripts/app.ts"
  ],"names": [
    "AppComponent","AppComponent.constructor"
  ],"mappings": "(...)"
}

好文件ts的源点列表:

enter image description here

我盯着Chrome / Chrome Canary中的项目(有/没有调试 – 效果相同).然后转到源(F12 – > Sources).我看到文件script / app.ts和script / boot.ts是空的:

enter image description here

当我尝试在IE11中打开脚本/ app.ts时,我收到错误:

Could not locate http://localhost:61272/appScripts/../../scripts/app.ts specified in source map http://localhost:61272/appScripts/app.js.map.

也许你知道什么是错的?我认为这个问题造成另一个问题:我无法调试..

解决方法

问题是浏览器找不到映射文件中引用的源文件.

sourceRoot选项可以帮助您指定sources文件夹.

我在调试模式下使用“inlineSourceMap”和“inlineSources”选项来克服“源路径地狱”.

更新1

示例最小tsconfig.json文件以生成内联源映射:

{
  "compilerOptions": {
    "target": "es5","inlineSourceMap": true,"inlineSources": true
  },"exclude": [
    "node_modules"    
  ]
}

你会得到类似的东西

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwLmpz...

在输出“.js”文件中.

但请注意Visual Studio 2015在某些情况下忽略tsconfig.json文件(例如Visual Studio 2015 – tsconfig.json – TypeScript 1.6.0 Beta)

为了让它只通过VS工作,我在构建后步骤中添加了“tsc”.为了使文件得到遵守,我构建了项目.

但对于生产,我建议你使用Grunt或Gulp构建任务,或Webpack.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读