Angular-Prod Build无法生成唯一的哈希 [英] Angular - Prod Build not generating unique hashes

查看:119
本文介绍了Angular-Prod Build无法生成唯一的哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

角度生产版本在我的项目中没有生成唯一的哈希值.

Angular production build is not generating unique hashes in my project.

以下是构建日志屏幕截图

无法在新的angular cli项目中重现此问题,似乎我的项目中存在一些问题.

Not able to reproduce this issue in new angular cli project, seems there is some issue in my project.

我正在使用角度-6.0.3

I am using angular - 6.0.3

下面是angular.json

Below is the angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "exampleProject": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {
        "@schematics/angular:component": {
          "styleext": "scss"
        }
      },
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/exampleProject",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              {
                "glob": "**/*",
                "input": "src/assets",
                "output": "/assets"
              },
              {
                "glob": "favicon.ico",
                "input": "src",
                "output": "/"
              },
              {
                "glob": "sitemap.xml",
                "input": "src/assets",
                "output": "/"
              },
              {
                "glob": "googled41787c6aae2151b.html",
                "input": "src/assets",
                "output": "/"
              },
              {
                "glob": "CNAME",
                "input": "src/assets",
                "output": "/"
              }
            ],
            "styles": [
              {
                "input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
              },
              "src/assets/css/reset.css",
              "src/assets/css/loading.css",
              "src/styles.scss",
              "node_modules/angular-bootstrap-md/scss/bootstrap/bootstrap.scss",
              "node_modules/angular-bootstrap-md/scss/mdb-free.scss"
            ],
            "stylePreprocessorOptions": {
              "includePaths": [
                "src/styles"
              ]
            },
             "scripts": [
              "src/assets/js/modernizr.js",
              "src/assets/js/gtm.js"

            ]
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "baseHref": "/",
              "serviceWorker": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "exampleProject:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "exampleProject:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "exampleProject:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              "src/styles.css"
            ],
            "scripts": [],
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "exampleProject-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "exampleProject:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "exampleProject:serve:production"
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "exampleProject"
}

请让我知道我在做什么错,或者提供任何解决方法.

Please let me know what I am doing wrong, Or provide any work around.

我尝试过

ng build --aot --output-hashing=all
ng build --output-hashing=all

即使在typescript或html中更改内容之后,仍然会为script.js产生相同的哈希值.

Still this produce same hashing for script.js, even after changing content in typescript or html.

推荐答案

还有很多其他人也面临与您同样的问题. 在此处检查.

There are plenty of other people that face the same issue with you. Check Here.

如果官方的角度cli github上没有一个,我认为您不会找到解决问题的方法,但是根据答复,您可以尝试使用以下内容更新您的配置并让我知道如果可行?

I don't think you'll find a solution to your problem if there isn't one on the official angular cli github, but based on the replies, can you please try updating your congifuration with the following and let me know if it works?

      "configurations": {
        "production": {
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.prod.ts"
            }
          ],
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "extractCss": true,
          "namedChunks": false,
          "aot": true,
          "extractLicenses": true,
          "vendorChunk": false,
          "buildOptimizer": true
        }
      }

预期文件会更改

您的实际代码仅在main.js中(我可以看到它得到了一个新的哈希).其余文件很少更改.在此处

main.js包含我们所有的代码,包括组件(ts,html和css 代码),管道,指令,服务和所有其他导入的模块 (包括第三方).

main.js contains all our code including components (ts, html and css codes), pipes, directives, services and all other imported modules (including third party).

scripts.js包含我们在的脚本部分中声明的脚本 angular.json文件

scripts.js contains the scripts we declare in the scripts section of angular.json file

"scripts": [
   "myScript.js",
]

这篇关于Angular-Prod Build无法生成唯一的哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆