How to stop Storybook opening a new webpage on start (automatically with zsh)
timreach
Posted on May 21, 2024
This started as a tip for Storybook users but it is probably useful for anyone who uses zsh -
Do you find it annoying that whenever you run $ yarn storybook
, Storybook takes the liberty of opening itself in a brand new tab? No fun if you're just restarting it because hot reload isn't working or something.
You may or may not know that there is an option to prevent this from happening: $ yarn storybook --ci
will start Storybook but not open a tab. Hoorah.
But even knowing this, I often forget and become annoyed for literally microseconds as I close the superfluous tab. Sure, I could just suck up the minor inconvenience, meditate more, drink less caffeine, get some perspective. Or, I could just automate a fix.
I don't want to impose my preference upon the whole team so I don't want to just add the flag to the scripts definition in package.json so instead let's just configure the terminal to add the flag in automatically.
Simply add the following to your ~/.zshrc
function yarn() {
if [[ "$1" == "storybook" ]]; then
command yarn storybook --ci "${@:2}"
else
command yarn "$@"
fi
}
P.S. don't forget to restart your terminal before testing it works...
This basically does a check any time yarn is run and if you're executing storybook will automatically add the flag. I'm sure you can imagine other uses of this pattern for similar issues where you want edit the default way a script executes on your machine but not your team's.
Posted on May 21, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.