简体   繁体   English

升级到 Angular 12 & Webpack

[英]Upgrade to Angular 12 & Webpack

I have upgraded an Angular 6 project to Angular 12 with .NET framework.我已经使用 .NET 框架将 Angular 6 项目升级到 Angular 12。 I'm facing 2 issues at the moment.我目前面临2个问题。

1) 1)

I have specified builds commands in package.json as:我在 package.json 中指定了构建命令:

"prodbuild": "ng build --configuration production --aot=true --output-hashing none",
"build": "ng build --output-hashing none",

and I'm able to compile using ng build --output-hashing none.我可以使用 ng build --output-hashing none 进行编译。 However, I'm not being able to debug the code using Chorme dev tools, the source displays from Webpack and not the directory structure of project.但是,我无法使用 Chorme 开发工具调试代码,源代码显示来自 Webpack 而不是项目的目录结构。 The code I'm changing in ts files is not updating in dev tools.我在 ts 文件中更改的代码未在开发工具中更新。 I have tried to clear cache, page refresh, but it is not helping.我试图清除缓存,刷新页面,但没有帮助。

  1. I've been using earlier我之前一直在使用

    ng build --watch ng build --watch

what has replaced this?什么取代了这个? This was very convenient to update code and refresh in browser.这对于在浏览器中更新代码和刷新非常方便。

Here is my angular.json:这是我的 angular.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "MyProj": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "allowedCommonJsDependencies": [
              "xlsx",
              "rxjs/BehaviorSubject",
              "rxjs/add/observable/throw",
              "rxjs/add/operator/catch",
              "rxjs/Observable",
              "rxjs/operators/map",
              "rxjs/operators/tap"
            ],
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "assets": [
              "src/assets",
              "src/favicon.ico"
            ],
            "styles": [
              "src/styles.scss",
              "node_modules/bootstrap/dist/css/bootstrap.min.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js",
              "node_modules/popper.js/dist/umd/popper.js",
              "node_modules/bootstrap/dist/js/bootstrap.min.js"
            ],
            "vendorChunk": true,
            "extractLicenses": false,
            "buildOptimizer": false,
            "sourceMap": true,
            "optimization": false,
            "namedChunks": true
          },
          "configurations": {
            "production": {
              "budgets": [
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            }
          },
          "defaultConfiguration": ""
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "MyProj:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "MyProj:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "MyProj:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "karmaConfig": "./karma.conf.js",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "scripts": [
            ],
            "styles": [
              "src/styles.scss"
            ],
            "assets": [
              "src/assets",
              "src/favicon.ico"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "MyProj-e2e": {
      "root": "",
      "sourceRoot": "",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "./protractor.conf.js",
            "devServerTarget": "MyProj:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "e2e/tsconfig.e2e.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "MyProj",
  "schematics": {
    "@schematics/angular:component": {
      "prefix": "app",
      "style": "scss"
    },
    "@schematics/angular:directive": {
      "prefix": "app"
    }
  }
}

Please advise!请指教!

ng build compiles with production configuration by default now. ng build现在默认使用生产配置进行编译。

Try ng build --watch --configuration development or ng serve尝试ng build --watch --configuration developmentng serve

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

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