如何在Angular Universal中进行缓存清除

问题描述 投票:0回答:1

如何在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"
  },
angular caching browser-cache angular8 angular-universal
1个回答
0
投票

当您运行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将生成带有散列名称的构建文件,因此,如果您在项目中进行了一些更改,则每次构建后都会看到不同的文件名。

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

© www.soinside.com 2019 - 2024. All rights reserved.