Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to open non default browsers when doing npm start for a react project

I have a react project that I am running using npm. When I do npm start, it launches on my default browser:- google chrome.

I would like to launch on firefox, safari and internet explorer for manual testing. I prefer don't making changes to package.json due to one time use.Any ideas on how to go about?

Specs

node -p process.arch: x64

node -p process.platform: darwin

npm info react version 16.4.0

macOS 10.13.4 (17E199)

like image 603
sdinesh94 Avatar asked Jun 04 '18 18:06

sdinesh94


3 Answers

Create an environment file .env at the root of the project directory and add following entry

BROWSER=firefox

For a complete list of .env file configuration, you can check here - https://facebook.github.io/create-react-app/docs/advanced-configuration

like image 126
palerdot Avatar answered Sep 21 '22 19:09

palerdot


As I read on the script that runs when you run npm start, you may set an environment variable called BROWSER before running the npm start

For example (on linux):

(export BROWSER=firefox;  npm start)

also, you may open the browsers after starting:

npm start &
firefox http://localhost:3000
safari http://localhost:3000

Save it to a something.sh and run this shell script. If you are on windows, you may do something similar on .bat script

like image 33
Murilo Cruz Avatar answered Sep 23 '22 19:09

Murilo Cruz


you can install global node package called opn-cli then you can run the command. https://www.npmjs.com/package/opn-cli

Sample command:

npm start & opn http://localhost:4200 -- firefox & opn http://localhost:4200 -- chrome

like image 30
kunalkamble Avatar answered Sep 23 '22 19:09

kunalkamble