如何在 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/