aklinker1 / vite-plugin-web-extension

Vite plugin for developing Chrome/Web Extensions
https://vite-plugin-web-extension.aklinker1.io/
MIT License
553 stars 48 forks source link

你好,我想在扩展中添加`new-tab`,从而实现自定义空白页 #45

Closed geeklibin closed 1 year ago

geeklibin commented 1 year ago

你好,我想在扩展中添加new-tab,从而实现自定义浏览器新标签的空白页。 但我尝试了在src/menifest.json中添加了:

"chrome_url_overrides": {
  "newtab": "newtab/index.html"
},

并且添加了:src/newtab/index.html 但是当我运行npm run dev(vite build --watch),编译完成后,却弹出无法加载清单。,并且未在dist文件夹中找到newtab/index.html文件,但是dist/menifest.json中的配置是存在 chrome_url_overrides.newtab配置的。

我应该如何配置和操作,希望得到你的帮助,非常感谢

aklinker1 commented 1 year ago

The plugin doesn't build the chrome_url_overrides by default (I should add this), but you can build additional files using the additionalInputs option. Make sure to use the absolute path to your html file.

// ./vite.config.ts
import webExtension from 'vite-plugin-web-extension';
import path from 'path';

export default defineConfig({
  plugins: [
    webExtension({
      // ...
      additionalInputs: [path.resolve(__dirname, "src/newtab/index.html")],
    },
  ],
})
geeklibin commented 1 year ago

The plugin doesn't build the chrome_url_overrides by default (I should add this), but you can build additional files using the additionalInputs option. Make sure to use the absolute path to your html file.

// ./vite.config.ts
import webExtension from 'vite-plugin-web-extension';
import path from 'path';

export default defineConfig({
  plugins: [
    webExtension({
      // ...
      additionalInputs: [path.resolve(__dirname, "src/newtab/index.html")],
    },
  ],
})

Thank you