部署后源文件 (.ts) 未显示在开发工具中

问题描述 投票:0回答:1

我只能在本地看到 .ts 源文件,但部署后,我在任何环境中都看不到它们。我已经将我的源映射设置为true,并且还在服务下设置了我的browserTarget。它仍然不起作用。请帮忙!

这是我的 angular.json 文件

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "UI-App": {
      "projectType": "application",
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": ["zone.js"],
            "tsConfig": "tsconfig.app.json",
            "inlineStyleLanguage": "scss",
            "assets": ["src/favicon.ico", "src/assets"],
            "styles": [
              "@fabric/components/legacy-theme.css",
              "@fabric/components/theme.css",
              "@fabric/primeng-styles/light-theme.css",
              "./node_modules/primeicons/primeicons.css",
              "./node_modules/primeng/resources/primeng.min.css",
              "./node_modules/primeflex/primeflex.css",
              "src/styles.scss"
            ],
            "scripts": [],
            "allowedCommonJsDependencies": ["color"]
          },
          "defaultConfiguration": "production",
          "configurations": {
            "production": {
              "optimization": {
                "scripts": true,
                "styles": true,
                "fonts": false
              },
              "outputHashing": "all",
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            },
            "development": {
              "buildOptimizer": false,
              "optimization": false,
              "vendorChunk": true,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "ui-angular-demo:build",
            "host": "localhost.gm.com",
            "ssl": true,
            "port": 8081
          },
          "configurations": {
            "production": {
              "browserTarget": "UI-App:build:production"
            },
            "development": {
              "browserTarget": "UI-App:build:development"
            }
          },
          "defaultConfiguration": "development"
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "UI-App:build"
          }
        },
        "lint": {
          "builder": "@angular-eslint/builder:lint",
          "options": {
            "lintFilePatterns": ["src/**/*.ts", "src/**/*.html"]
          }
        }
      }
    }
  },
  "cli": {
    "schematicCollections": ["@angular-eslint/schematics"]
  },
  "schematics": {
    "@schematics/angular:component": {
      "style": "scss",
      "standalone": true
    },
    "@schematics/angular:directive": {
      "standalone": true
    },
    "@schematics/angular:pipe": {
      "standalone": true
    },
    "@schematics/angular:application": {
      "strict": true
    },
    "@angular-eslint/schematics:application": {
      "setParserOptionsProject": true
    },
    "@angular-eslint/schematics:library": {
      "setParserOptionsProject": true
    }
  }
}

这是我的 package.json 的片段

"name": "UI-App",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "jest",
    "lint": "ng lint",
    "lint:fix": "ng lint --fix",
    "format": "prettier --write src",
    "format:check": "prettier --check src",
    "e2e": "ng e2e",
    "clean": "node scripts/clean.mjs"
  },

这是我本地的开发工具。我可以看到 src 文件夹。 这是我部署应用程序后的开发工具。看不到 src 文件夹。

angular typescript google-chrome-devtools package.json angular.json
1个回答
0
投票

源映射文件允许开发工具将 JS 文件“转换”回 TS。

确实不可读。

如果你希望在构建时获得与本地环境相同的结果,那么你应该运行

npx ng serve -c development 

这将使用开发环境,该环境被配置为将源文件保留在您的配置中。

需要注意的是,建议不要在生产版本中这样做。

© www.soinside.com 2019 - 2024. All rights reserved.