Reputation: 1178
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)
Upvotes: 5
Views: 10497
Reputation: 641
First Install This:-
npm install --save cross-env
Than and update package.json file scripts
only :-
Old
"scripts": {
"start": "cross-env BROWSER=none react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Update
"scripts": {
"start": "cross-env BROWSER=none react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Upvotes: 0
Reputation: 7642
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
Upvotes: 10
Reputation: 294
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
Upvotes: 2
Reputation: 2511
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
Upvotes: 3