vite-plugin-crx-mv3 icon indicating copy to clipboard operation
vite-plugin-crx-mv3 copied to clipboard

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

Open Llyonss opened this issue 1 year ago • 1 comments

背景

我的目录层级如下:

  • src
    • crx
      • popup
        • index.html
      • manifest.json 其中manifest代码如下:
{
   ... 
   "action": {
    "default_popup": "./popup/index.html"
    },
   ...
}

问题

此时生成的dist的目录如下,符合预期:

  • src
    • crx
      • popup
        • index.html
  • manifest.json

但是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文件生成到根目录。

Llyonss avatar Oct 28 '23 06:10 Llyonss