简体   繁体   English

Angular CLI生成用于打字稿的源地图,但浏览器仅加载样式源地图

[英]Angular CLI produces sourcemaps for typescript but browser is only loading style source maps

I started in a new Project, and the Team was using Webpack for building its angular application. 我从一个新项目开始,团队正在使用Webpack构建其角度应用程序。 That Webpack configuration never supported source maps at all. 该Webpack配置根本不支持源映射。 Now we upgraded to Angular 8 and in that turn, we decided to use the Angular-CLI. 现在我们升级到了Angular 8,于是,我们决定使用Angular-CLI。

The CLI should support Source Maps out of the box, but somehow it is only loading the styles for all components CLI应该开箱即用地支持Source Maps,但是以某种方式它仅加载所有组件的样式

Chrome开发人员工具

But whenever i directly check the sourcemaps from the main.js, I can find all the mapped code. 但是只要我直接从main.js中检查sourcemap,就可以找到所有映射的代码。

Is it possible, that we missed some config, or some importeted package deactivated the sourcemaps? 是否有可能我们错过了某些配置,或者某些重要软件包取消了源地图? For a new cli project, sourcemaps are working fine 对于一个新的cli项目,sourcemaps运行良好

angular.json angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "test2": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "unfvor",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "sourceMap": true,
            "outputPath": "dist/vorschlag",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": false,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": true,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "test2:build",
            "port": 7002
          },
          "configurations": {
            "production": {
              "browserTarget": "test2:build:production"
            }
          },
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "test2:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "test2:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "test2:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "vorschlag"
}

tsconfig.app.json tsconfig.app.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": []
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "src/test.ts",
    "src/**/*.spec.ts"
  ]
}

tsconfig.json tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom",
      "esnext"
    ]
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}

For those, who have the same problem. 对于那些有同样问题的人。 I could fix it with these steps 我可以通过以下步骤修复它

  1. Create a new ng CLI project, 创建一个新的ng CLI项目,
  2. move all assets and code to the new project 将所有资产和代码移至新项目
  3. make the new project run 使新项目运行
  4. replace the angular folder in your repository with the newly created project 用新创建的项目替换存储库中的角度文件夹

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

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