aklinker1 / vite-plugin-web-extension

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

Invalid TARGET Option for multibrowser support #171

Closed GODrums closed 6 months ago

GODrums commented 6 months ago

Summary

When using the TARGET= option for multibrowser support, the execution fails. This command is used in the package.json to define the target browser. Many demos in the official repository utilize it (see e.g. demo-vue):

"build:firefox": "TARGET=firefox vite build --mode production"

Related documentation page: Multibrowser Support - Manifest Templates

The error:

'TARGET' is not recognized as an internal or external command,
operable program or batch file.
 ELIFECYCLE  Command failed with exit code 1.

Reproduction (using one of the example projects)

Clone this repository:

git clone https://github.com/aklinker1/vite-plugin-web-extension.git

Navigate to one of the sample projects:

cd .\packages\demo-vue

Run the failing command:

pnpm run build:firefox

Environment

  System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 AMD Ryzen 7 7800X3D 8-Core Processor
    Memory: 17.47 GB / 31.21 GB
  Binaries:
    Node: 20.10.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.2.5 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.12.1 - ~\AppData\Roaming\npm\pnpm.CMD
    bun: 1.0.18 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (120.0.2210.91)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    vite: ^5.0.0 => 5.0.2
    vite-plugin-web-extension: workspace:* => 4.1.0
aklinker1 commented 6 months ago

@GODrums This is how you set an environment variable in Linux/Mac, it doesn't work on Windows, at least not in CMD and Powershell. It works with WSL and git bash.

Solution: cross-env

pnpm i cross-env
- "dev:firefox": "TARGET=Firefox vite",
+ "dev:firefox": "cross-env TARGET=Firefox vite",

I can add a section to the docs with this info.

GODrums commented 6 months ago

Thank you for the extensive explanation! Your suggested solution works exactly as intented.

I would love a short section about this for us Windows users, although I probably should have been able to figure this out myself.

aklinker1 commented 6 months ago

Added docs in https://github.com/aklinker1/vite-plugin-web-extension/commit/830394587ef60ab6a3e19f41e7771bdabb2b4c80