webpack MV3 webworker 目标使用
我正在尝试将旧的 Chrome MV2 项目转换为 MV3。构建系统使用 webpack。我从文档中了解到,我应该将目标设置为“webworker”来为 MV3 构建 Service Worker 来替换我的 MV2 背景页面。
我的 webpack.config.js 文件中包含以下代码:
module.exports = {
...
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'esbuild-loader',
options: {
loader: 'ts',
target: 'webworker'
}
},
],
},
当我使用此配置时,仅将之前的“es2015”更改为“webworker”,构建失败 出现以下错误:
Error: Invalid target: "webworker" (valid: esN, chromeN, edgeN, firefoxN, iosN, nodeN, safariN)
文档提示可能涉及 WebpackOptionsApply 插件,但我使用该插件时出现故障。我尝试过为该插件设置参数,但没有发现任何有效的方法。
plugins: [
new WebpackOptionsApply(),
我能找到的关于使用 webpack 进行 MV3 服务工作者的文档似乎并不多,而且我也不是 typescript 或 webpack 专家。从 typescript 或 webpack 迁移对我们来说不是一个可行的选择。如果我恢复使用“es2015”作为目标,我会从一些(未识别的)包含的库中提取“窗口”引用,我需要在 MV3 中消除这些引用。我希望使用“webworker”来识别并消除哪个库。
I'm trying to convert an old Chrome MV2 project to MV3. The build system uses webpack. I understand from the documentation that I should set the target as "webworker" to build a service worker for MV3 to replace my MV2 background page.
I have the following code included in my webpack.config.js file:
module.exports = {
...
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'esbuild-loader',
options: {
loader: 'ts',
target: 'webworker'
}
},
],
},
When I use this configuration, changing only the previous "es2015" to "webworker", the build fails
with the following error:
Error: Invalid target: "webworker" (valid: esN, chromeN, edgeN, firefoxN, iosN, nodeN, safariN)
The documentation hints that the WebpackOptionsApply plug-in may be involved, but I get a failure when I use that. I have tried setting up arguments to this plug-in, but I haven't found any that work.
plugins: [
new WebpackOptionsApply(),
There doesn't seem to be much documentation around using webpack for MV3 service workers that I can find and I'm no typescript or webpack expert. Moving from typescript or from webpack isn't a viable option for us. If I revert to using "es2015" as the target, I get "window" references being drawn-in from some (unidentified) included library that I will need to eliminate for MV3. I'm hoping to use "webworker" to identify and eliminate whichever library that is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论