使用 CLI 清除客户端缓存 [英] Client side cache busting using the CLI
问题描述
我们正在使用 aurelia-cli
.任务包括:
We're using the aurelia-cli
. The tasks include these:
build.json
build.ts
process-css.ts
process-markup.ts
process-sass.ts
run.json
run.ts
test.json
test.ts
transpile.ts
如果我们完全使用 cli 执行缓存破坏解决方案如何?
How if at all do we do a cache-busting solution the with cli?
我们已经尝试过的是增加 scripts
目录的数量,使其成为 scripts1
, scripts2
, >scriptsN
.
What we've tried already is to increment the number of the scripts
directory, so that it goes scripts1
, scripts2
, scriptsN
.
推荐答案
0.20.0 Support
今天是我的幸运日.8 小时后发布 aurelia-cli
前是这样说的:
0.20.0 Support
It's my lucky day. An aurelia-cli
release from 8 hours ago says this:
特点:支持捆绑版本号
演练
首先,安装 0.20.0 并创建一个新应用.
Walkthru
First, install 0.20.0 and create a new app.
npm install aurelia-cli@">=0.20.0" -g
au new my-app
或者,升级现有应用.
npm install aurelia-cli@">=0.20.0" --save-dev
接下来,打开my-app/aurelia-project/aurelia.json
.
将 build.options.rev
属性设置为 true.
Set the build.options.rev
property to true.
"options": {
"minify": "stage & prod",
"sourcemaps": "dev & stage",
"rev": true
},
在 build.targets
"targets": [
{
"id": "web",
"displayName": "Web",
"output": "scripts",
"index": "index.html"
}
],
aurelia-cli
将查找 index
文件并替换对 scriptsvendor-bundle.js
的引用,如下所示:
The aurelia-cli
will look for the index
file and replace the reference to scriptsvendor-bundle.js
like this:
<script src="scriptsvendor-bundle.js" data-main="aurelia-bootstrapper">
<script src="scriptsvendor-bundle-947c308e28.js" data-main="aurelia-bootstrapper">
最后,构建应用程序.
au build --env prod
您的捆绑包将如下所示:
Your bundles will look something like this:
app-bundle-e0c4d46f7d.js
vendor-bundle-dba9184d78.js
GitHub 上的源代码
let defaultBuildOptions = {
minify: "stage & prod",
sourcemaps: "dev & stage",
rev: false
};
if (buildOptions.rev) {
//Generate a unique hash based off of the bundle contents
this.hash = generateHash(concat.content);
bundleFileName = generateHashedPath(this.config.name, this.hash);
}
这篇关于使用 CLI 清除客户端缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!