developit / developit/workerize-loader
[path] replacer token passed to workerize-loader has stopped working in Webpack 5
還沒有人認領這個 Issue。
- 主要語言
- JavaScript
- 星號
- 2.3k
- 分支
- 85
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Used to be the case with Webpack 4 that we could pass [path][name].[contenthash] as the name template for workerize-loader to use; and we'd get workers output into a folder structure mirroring their original source location.
This was nice for debugging purposes to easily identify workers, because the entry point file for esp. larger workers is usually some kind of index.js file. [path] means you don't need to inspect every separate worker named index.[hash].worker.js - and it prevented name collisions when you would generate names in development builds without hash fingerprints in them.
As of Webpack 5, that functionality appears to be broken. It resolves [name] and [contenthash] just fine, but doesn't know how to deal with [path].
I'm using a plugin to dynamically inject options into loaders to configure bare loader URLs such as
import worker from "workerize-loader!./path-to/worker"
centrally, and luckily I was able to extend the logic there to use the current compilation context and module context to compute a relative path, but yeah... this is not very ergonomic, easily understood or maintainable:
new InjectOptionsPlugin({
loaders : {
"workerize-loader" : ( module, compilation ) => {
const context = path
.relative( compilation.options.context, module.context );
.replace( /\\/g, "/" );
return {
name : dev ? `${context}[name]` : "${context}[name].[contenthash]`
};
}
}
})
compared to what it used to be:
new InjectOptionsPlugin({
loaders : {
"workerize-loader" : {
name : dev ? "[path][name]" : "[path][name].[contenthash]"
}
}
})
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
使用此處描述的裸 loader URL 和 [path][name].[contenthash] 範本,在 Webpack 5 下重現 workerize-loader 的問題。追蹤 loader 如何處理其 name 選項,並將 [path] 與可正常運作的 [name] 和 [contenthash] token 進行比較;當 worker 輸出能保留相對於來源檔案的路徑,且不需要從外部注入選項時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- javascript, webpack
- 領域
- build-system, tooling
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100