使用CLI清除客户端缓存 [英] Client side cache busting using the CLI

查看:204
本文介绍了使用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目录的编号,以使它进入scripts1scripts2scriptsN.

What we've tried already is to increment the number of the scripts directory, so that it goes scripts1, scripts2, scriptsN.

推荐答案

0.20.0支持

这是我的幸运日. 从8小时前发布的aurelia-cli版本说:

0.20.0 Support

It's my lucky day. An aurelia-cli release from 8 hours ago says this:

功能:支持捆绑软件修订版号

Features: Support bundle revision numbers

Walkthru

首先,安装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

或者,升级现有的应用程序.

Or, upgrade an existing 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文件,并替换对scripts\vendor-bundle.js的引用,如下所示:

The aurelia-cli will look for the index file and replace the reference to scripts\vendor-bundle.js like this:

<script src="scripts\vendor-bundle.js" data-main="aurelia-bootstrapper">
<script src="scripts\vendor-bundle-947c308e28.js" data-main="aurelia-bootstrapper">

最后,构建应用程序.

Finally, build the app.

au build --env prod

您的捆绑包将如下所示:

Your bundles will look something like this:

app-bundle-e0c4d46f7d.js
vendor-bundle-dba9184d78.js

GitHub上的来源

cli/lib/build/bundler.js

let defaultBuildOptions = {
  minify: "stage & prod",
  sourcemaps: "dev & stage",
  rev: false
};

cli/lib/build/bundler.js

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屋!

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