我不認爲彙總有類似webpack dll plugin的東西,所以,我的答案可能看起來不相關,但我認爲你可以認爲它是一個很好的起點,並開始尋找類似的彙總。
庫生活在一個CDN:
- 與其對應的
DLL Reference
這究竟說明了如何需要導出組件創建DLL
。
- 使用自解釋路徑並保持其一致性,如
https://cdn.mydomain.com/<libraryName>/<version>/<libraryName>.{js,json,d.ts}
(請求者應添加?<cacheBustingUID>
以避免客戶端緩存問題)。除了正常的版本控制之外,我還建議您使用關鍵字作爲version
字段,這樣可以實現always true path
,它指向最新版本的軟件包:(https://cdn.mydomain.com/foo/1.0.0/foo.{js,json,d.ts}
和https://cdn.mydomain.com/foo/latest/foo.{js,json,d.ts}
)。
- 解決所有文件,並開始開發服務器(記住的WebPack允許返回一個承諾作爲一個配置)
module.exports = env => {
const libs = ((name, version, exts) => (
exts.map(ext => `https://cdn.mydomain.com/${name}/${version}/${name}.${ext}`)
))('foo', 'latest', ['js', 'd.ts', 'json'])
return Promise
.all(libs.map(fetch))
.then([library, definitions, DLLReference] => {
// what to do?
// you can also inject the dynamic paths through `webpackDefinePlugin`
})
}
該解決方案是相當不錯的,在所有的點,但我會建議您保持簡單的想法:在打字稿中爲你的圖書館創建一個項目。 – jeorfevre