firebase Angular -产品构建未生成唯一散列

jpfvwuh4  于 2022-12-24  发布在  Angular
关注(0)|答案(4)|浏览(130)

在我的项目中,Angular 生产构建没有生成唯一的哈希。

    • 以下是构建日志屏幕截图**

无法在新的angular cli项目中重现此问题,似乎我的项目中存在一些问题。
我使用的是Angular -6.0.3
下面是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"
}

请让我知道我做错了什么,或提供任何解决办法。

    • 编辑:**

我试过了

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

这仍然会为script.js产生相同的散列,即使在更改了typescript或html中的内容之后。

阅读答案前请阅读此内容

我在firebase中遇到了一个问题,我误解了编译的代码将被捆绑为scripts.js,但没有,捆绑的代码是main.js
我真正的问题是
我有一个firebase缓存规则,即使禁用它后,它仍然从缓存中加载之前访问过我的应用程序的用户,所以我删除并创建了一个新的firebase项目,解决了我的问题。

htzpubme

htzpubme1#

还有很多其他人也面临着同样的问题。
我不认为你会找到一个解决你的问题,如果没有一个官方的Angular cli github,但根据答复,你可以尝试更新您的配置与以下,让我知道如果它的工作?

"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
        }
      }

Edit:预期要更改的文件

您的实际代码只在main.js中(我可以看到它得到了一个新的散列),其余的文件很少更改。
main.js包含我们所有的代码,包括组件(TS,HTML和CSS代码),管道,指令,服务和所有其他导入模块(包括第三方)。
scripts.js包含我们在angular.json文件的scripts部分声明的脚本

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

c9qzyr3d2#

如果使用的是Angular 7+,则可以使用以下命令

ng build --configuration production --output-hashing all

确保在angular.json文件中设置了配置。

swvgeqrz

swvgeqrz3#

我观察到的主要问题是,当我们在应用程序中进行任何代码更改时,散列只会更改。但对于样式和多边形填充,标记是相同的。
| 初始块文件|姓名|大小|
| - ------| - ------| - ------|
| main-es5.4daebf996f3ead829477.js|主|759.75千字节|
| main-es2015.4daebf996f3ead829477.js|主|682.24千字节|
| styles.427122a7a8ba74646062.css|花柱|477.01千字节|
| polyfills-es5.d7b40cf62085282501b1.js|聚酯填充物-es5| 131.97千字节|
| polyfills-es2015.2823b1a5ccf71efe2bde.js|聚合填充|36.11千字节|
| runtime-es2015.a4dadbc03350107420a4.js|运行时间|1.45千字节|
| runtime-es5.a4dadbc03350107420a4.js|运行时间|1.45千字节|
构建日期:2022年6月6日T09:50:45.524Z-哈希:5658eef36186f2e20989-时间:150810毫秒
| 初始块文件|姓名|大小|
| - ------| - ------| - ------|
| main-es5.d9483ea4d4880b3e0771.js|主|759.67千字节|
| main-es2015.d9483ea4d4880b3e0771.js|主|682.15千字节|
| styles.427122a7a8ba74646062.css|花柱|477.01千字节|
| polyfills-es5.d7b40cf62085282501b1.js|聚酯填充物-es5| 131.97千字节|
| polyfills-es2015.2823b1a5ccf71efe2bde.js|聚合填充|36.11千字节|
| runtime-es2015.a4dadbc03350107420a4.js|运行时间|1.45千字节|
| runtime-es5.a4dadbc03350107420a4.js|运行时间|1.45千字节|
构建日期:2022年6月6日T09:54:59.714Z-哈希:2431d248bc6f790fcb91-时间:145432毫秒

rkue9o1l

rkue9o1l4#

我在我的项目中发现了这个问题(Angular cli 14.2.10,我从13v升级),我意识到一件重要的事情:如果我改变app.component.html|ts或与此组件相关的其他组件,并在构建我的项目后,散列文件的名称与以前的散列文件不同。但如果我改变其他组件,然后构建我的项目,生成的文件的散列值与以前的散列值相同。因此,对于这种情况,解决方案是在app.component中做一些不必要的更改。

相关问题