parcel.js --open 'google chrome' 中的命令不适用于 Windows,仅适用于 MacOS

Command in parcel.js --open 'google chrome' does not work on Windows, only works on MacOS

我使用 parcel.js 来设置我的项目。此命令 --open 'google chrome' 不适用于 Windows,仅适用于 MacOS。错误是:Windows 找不到 'google'。请确保您输入的名称正确,然后重试。

传递给 --open [browser] 的浏览器值是 platform-dependent:

  • Windows: chrome
  • Linux: google-chrome
  • MacOS:google chrome

包裹uses the opn package to start the browser. From the opn documentation:

Type: string | string[]

Specify the app to open the target with, or an array with the app and app arguments.

The app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is google chrome on macOS, google-chrome on Linux and chrome on Windows.

You may also pass in the app's full path. For example on WSL, this can be /mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe for the Windows installation of Chrome.