angular - 如何在 Angular Universal 中缓存破坏

标签 angular caching browser-cache angular8 angular-universal

如何在 Angular Universal 中运行缓存清除命令? 我尝试运行 npm run build:ssr --output-hashing=all 但它没有更改/添加任何内容。

PACKAGE.json

  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "compile:server": "webpack --config webpack.server.config.js --progress --colors",
    "serve:ssr": "node dist/server",
    "build:ssr": "npm run build:client-and-server-bundles && npm run compile:server",
    "build:client-and-server-bundles": "ng build --prod && ng run sample-project:server:production --bundleDependencies all"
  },

最佳答案

当你运行npm run build:ssr --output-hashing=all时,npm只会执行npm run build:ssr,而不会考虑提供选项。

为此,在 package.json 中添加以下脚本并运行 npm run build:ssr:outhashall

...
"scripts" {
    "build:ssr:outhashall": "npm run build:client-and-server-bundles:outhashall && npm run compile:server",
    "build:client-and-server-bundles:outhashall": "ng build --prod --output-hashing=all && ng run sample-project:server:production --bundleDependencies all"
}
...

评论要点:

请注意,--output-hashing=all 将生成具有哈希名称的构建文件,因此,如果您在项目中进行了一些更改,那么每次构建后您将看到不同的文件名。

因此,在部署应用程序时,您需要删除现有文件并将新文件放入部署文件夹中。

关于angular - 如何在 Angular Universal 中缓存破坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59450293/

相关文章:

caching - 堆叠缓存引擎

caching - nginx - 是否可以配置代理缓存,以便在没有 HTTP header 的情况下保存文件或以更 "human friendly"格式保存文件?

javascript - 检测图像是否被缓存

sql-server - MS SQL Server 2008 是否缓存二进制数据字段?即VARBINARY

php - 如何使用javascript捕获缓存清除事件?

Angular - 使用 PrimeNg 表进行 Jasmine 测试 - 无法验证单元测试中的行数

angularjs - 错误: 'reflect-metadata shim is required' when upgrading to Webpack 2

javascript - angular2中templatURL中的动态模板

html - 如何防止动态添加的父类添加到 Angular Material,mat-selection-list 中的子元素?

c - 使用自修改代码观察 x86 上的陈旧指令提取