在构建后或部署期间在ngsw中重新生成内容哈希 [英] Regenerate content hash in ngsw after build or during deploy

查看:57
本文介绍了在构建后或部署期间在ngsw中重新生成内容哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用Angular Service Worker的Angular应用程序.

We have an Angular application that uses the angular service worker.

我们知道,该服务工作者将缓存文件中的内容哈希与 ngsw.json 文件中的哈希进行比较.

As we know, this service worker compares content hashes from cached files against the hashes in the ngsw.json file.

现在,我们已经设置了持续集成和交付(使用Azure DevOps,但没有关系),并且在交付阶段,我们正在修改 environment.json 文件中的某些设置(如配色方案,API url ...都与部署目标有关).问题是,通过修改json文件,哈希不再与 ngsw.json 文件中该文件的哈希匹配.

Now, we have set-up continuous integration and delivery (with Azure DevOps, but shouldn't matter) and during the delivery phase, we're modifying some settings in an environment.json file (like color scheme, API url... all related to the deployment target). The problem is, by modifying that json file, the hash no longer matches with the hash for that file in the ngsw.json file.

我们绝对不希望针对专用目标环境进行重建,因为这会破坏CI/CD中的目标.(一旦该软件包进入质量检查流程,您就不想为生产环境重建该软件包了.)

We definitely don't want to rebuild for a dedicated target environment as that defeats the purpose in CI/CD. (You don't want to rebuild a package for a production environment once that package went to the QA process).

所以问题是:在修改了我们的 environment.json (或任何其他)文件之后,有没有办法重新生成 ngsw.json 文件中的哈希?还是对此问题有其他解决方案?

So the question is: is there a way to regenerate the hashes in the ngsw.json file after we have modified our environment.json (or any other) file? Or is there an other solution to this problem?

推荐答案

您是否在谈论以下命令:

Are you talking about the following command:

node_modules/.bin/ngsw-config dist src/ngsw-config.json

您可以将命令放置在package.json中:

You can place the command in your package.json:

  "scripts": {
    "ngsw-config": "node_modules/.bin/ngsw-config dist src/ngsw-config.json"
  }

这将为您重做配置并散列.在执行最后一条命令后运行它,这应该在您的CI环境中是可能的.

This redoes the config and hashes for you. Run it after your final command, this should be possible in your CI environment.

请注意,如果您使用其中之一,则可以使用基本href参数.

Note also it can take a base href parameter if you use one of those.

此处有更多说明: Angular文档

这篇关于在构建后或部署期间在ngsw中重新生成内容哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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