Next.js Discord

Discord Forum

Package.json predev script optimization

Unanswered
Buff-bellied Hummingbird posted this in #help-forum
Open in Discord
Avatar
Buff-bellied HummingbirdOP
Hey folks,

Looking for a solution to opening a new tab that mirrors create-react-app's approach. I'd like to only open a new tab on npm run dev if an existing tab at the specified port is not already open, otherwise focus that existing tab. Curious if anyone has bumped into this and found a solution already.

5 Replies

Avatar
I don't think the focusing thing is every possible but you can write a script which waits for few seconds(until the dev server is ready) to open the new tab, something like what prisma studio does
Avatar
@Yi Lon Ma I don't think the focusing thing is every possible but you can write a script which waits for few seconds(until the dev server is ready) to open the new tab, something like what prisma studio does
Avatar
Buff-bellied HummingbirdOP
More important than focusing is to not open a new tab if I already have one open at the specific host.

This is default behavior in CRA and as I’m working on migrating an app and find myself restarting frequently it’s kind of painful ha
Avatar
I don't remember that behaviour, I think it just opens a new tab no matter what
need to see for myself
Avatar
Yoir only option is to write a script that runs in a seperate terminal that monitors the port to check for the dev server being actove and then looking at whatever browser you use to see if its possible to know what tabs are open by code