2016-09-23 117 views
4

我们使用的是aurelia-cli。任务包括以下:使用CLI客户端缓存破坏

build.json 
build.ts 
process-css.ts 
process-markup.ts 
process-sass.ts 
run.json 
run.ts 
test.json 
test.ts 
transpile.ts 

如何,如果在所有我们做与CLI缓存无效化解决方案?

我们已经尝试过的是增加scripts目录的编号,使其变为scripts1,scripts2,scriptsN

+0

http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/the-aurelia-cli/10 – rball

回答

8

0.20.0支持

这是我的幸运日。 An aurelia-cli release from 8 hours前这样说:

产品特点:支持包的版本号

Walkthru

首先,安装0.20.0并创建一个新的应用程序。

npm install [email protected]">=0.20.0" -g 
au new my-app 

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

npm install [email protected]">=0.20.0" --save-dev 

接下来,打开my-app/aurelia-project/aurelia.json

设置build.options.rev属性。

"options": { 
    "minify": "stage & prod", 
    "sourcemaps": "dev & stage", 
    "rev": "true" 
}, 

设置outputindex属性里面的build.targets

"targets": [ 
    { 
     "id": "web", 
     "displayName": "Web", 
     "output": "scripts", 
     "index": "index.html" 
    } 
], 

aurelia-cli将寻找index文件并替换参考scripts\vendor-bundle.js这样的:

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

最后,建立应用程序。

你的包会是这个样子:

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);  
} 
+1

您有一个额外的步骤,你不需要。您只需要将''index''属性添加到构建目标,而不是平台。很高兴这对你有用!此外,随时标记自己的答案为*答案:) – Andrew

+0

谢谢@安德鲁。更新。 –

+0

随意标记自己的答案为*答案,这样别人可以看到它解决:) – Andrew

3

我的Aurelia应用程序托管在一个ASP.Net Core MVC页面中,并且使用ASP.Net Core asp-append-version标签帮助程序确保浏览器正确加载更新的JS捆绑包已取得了良好的成功。

此属性可以添加到脚本标记,并且ASP.Net会根据脚本文件的内容自动附加版本#。散列是在应用程序启动时生成的,因此必须重新启动应用程序才能使用ASP。网络来检测任何新的变化。

在得到这个与Aurelia路上工作的诀窍在于还加入了APP-bundle.js文件作为托管网页上的脚本标签:

<body aurelia-app="main-public" class="public"> <script src="scripts/vendor-bundle.js" data-main="aurelia-bootstrapper" asp-append-version="true"></script> <script src="scripts/app-bundle.js" asp-append-version="true"></script> </body>

输出看起来是这样的:

<body aurelia-app="main-public" class="public"> <script src="scripts/vendor-bundle.js?v=97hNIHUQnLL3Q44m2FWNV-3NIpgqvgIDIx5sUXUcySQ" data-main="aurelia-bootstrapper"></script> <script src="scripts/app-bundle.js?v=htYOQIr-GHrpZIDiT2b32LxxPZs10cfUU4YNt9iKLro"></script> </body>

声明:我还没有关于的装载行为检查该厂商bundle.js源代码pp-bundle.js,所以我不知道这个解决方案有多强大。我没有遇到过这种方法的任何问题,并且对我的情况来说工作得很好;但是,请在使用生产代码之前谨慎使用并进行充分测试。

+0

我正在寻找类似的东西。通常,您只需要包含目标包(默认为vendor-bundle),并且看起来好像生成了脚本标记(通过requireJS,也许?)并插入到应用程序包的头部。你看到相同的东西吗? –

+0

刚试过这个。看起来,如果你做你正在做的事情,requireJS不需要加载脚本本身,所以不会将脚本插入到HEAD中!太好了! –

+0

这是正确的。但是,如果手动添加脚本标记,则会使用该标记,而不会尝试两次加载脚本。 –