2016-09-23 96 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

這是正確的。但是,如果手動添加腳本標記,則會使用該標記,而不會嘗試兩次加載腳本。 –