Jervis2049 / vite-plugin-crx-mv3

Build a Chrome Extension with Vite⚡
201 stars 30 forks source link

打包时生成manifest.json中的default_popup的地址也许可以优化 #33

Open Llyonss opened 10 months ago

Llyonss commented 10 months ago

背景

我的目录层级如下:

但是dist中生成的 manifest.json代码如下,不符合预期:

{
   ... 
   "action": {
    "default_popup": "index.html"
    },
   ...
}

期望

期望生成如下路径

{
   ... 
   "action": {
    "default_popup": "./src/crx/popup/index.html"
    },
   ...
}

分析

阅读源码时发现问题来源自下方 src/processors/manifest.ts 中的 generateManifest 函数的代码:

...
generateManifest (){
   ...
    if (manifest.action?.default_popup) {
      manifest.action.default_popup = basename(manifest.action.default_popup)
    }
   ...
}
...

如果可以的话,希望其中使用 basename() 函数生成 popup 这里可以加一点适配不同的目录结构的逻辑,比如:

...
generateManifest (){
   ...
    if (manifest.action?.default_popup) {
      manifest.action.default_popup = manifest.action.default_popup.replace( /^\./, this.srcDir);
    }
   ...
}
...

或者把popup的index.html文件生成到根目录。

Jervis2049 commented 9 months ago

感谢你提出的问题。不过现阶段比较忙,无力维护☹️,短期无法提供方案。