aklinker1 / vite-plugin-web-extension

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

Getting "You must supply options.input to rollup" error when building #31

Closed jbmusso closed 2 years ago

jbmusso commented 2 years ago

Greetings, and thanks for writing this plugin.

I'm getting the following error when running vite build --watch:

You must supply options.input to rollup

Here's my vite.config.ts file:

import fs from "node:fs"
import path from "node:path"
import { defineConfig } from "vite"
import webExtension from "vite-plugin-web-extension"

const manifest = JSON.parse(fs.readFileSync(path.resolve(__dirname, "_src/manifest.json"), "utf8"))

export default defineConfig({
  root: "dist",
  // Configure our outputs - nothing special, this is normal vite config
  build: {
    outDir: path.resolve(__dirname, "build/web-extension"),
    emptyOutDir: true
  },
  // Add the webExtension plugin
  plugins: [
    // @ts-expect-error - TODO: fix module stuff later
    webExtension.default({
      manifest: () => {
        return manifest
      },
      assets: path.resolve(__dirname, "_src/assets")
    })
  ]
})

And the content of manifest.json, if that helps:

{
  "manifest_version": 3,
  "name": "Some WebExtension",
  "version": "1.0",
  "description": "Adds a red border to some webpages.",
  "permissions": ["webRequest", "webRequestBlocking"],
  "host_permissions": ["*://*.example.com/*"],
  "icons": {
    "48": "icons/flower-48.png"
  },
  "background": {
    "service_worker": "background.js",
    "type": "module"
  }
}

I see there's a test snapshot which also contains this error: https://github.com/aklinker1/vite-plugin-web-extension/blob/65548601c7e81a4232ddfcaf9f70b720e25904bf/tests/__snapshots__/e2e.test.ts.snap#L47

Could it be related to this line in the lib source code? https://github.com/aklinker1/vite-plugin-web-extension/blob/65548601c7e81a4232ddfcaf9f70b720e25904bf/lib/src/build-script.ts#L56

I'm fairly new to vite and not really seasoned with rollup. Is there anything that I should be tweaking on my side and/or is this something that relates to vite-plugin-web-extension? I'll be happy to provide more details if that helps.

(Not related: I'm having ES6/TS module issues in vite.config.ts but I haven't bothered fixing them yet #YakShaving.)

aklinker1 commented 2 years ago

Right now, this plugin doesn't support building extensions without a UI.

To get around this, you can create a dummy, empty HTML file:

<html></html>

And include it as an additional input:

webExtension({
  ...
  additionalInputs: ["dummy.html"],
})
jbmusso commented 2 years ago

Thanks for this workaround, I can confirm this solves the issue 🙏.