41

[2018-11-06 Tue 08:40] TIL: serving static files in storybook

 5 years ago
source link: https://www.tuicool.com/articles/hit/qmuUbeb
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

[2018-11-06 Tue 08:40] TIL: serving static files in storybook

  • last_update: Time-stamp: <2018-11-06 08:56:46 tamara>
  • capture_date: [2018-11-06 Tue 08:40]
  • keywords: storybook, test data, static assets

I wish I’d known about this before taking all that time to munge the test data the first time. It turns out storybook can serve up static assets by providing the -s option on the command line:

start-storybook -p 9009 -s ./path/to/static/assets -c .storybook/config.js

You can have more than one folder as well, separating them by commas

start-storybook -p 9009 -s ./some/assets,./other/assets,./these/assets/over/here -c .storybook/config.js

This makes them available at the root URL

http://localhost:9009/

So if you have assets at ./src/components/AttachmentList/__TEST_DATA__/attachments/ , for example, shasta/32/original/002.jpg , then the URL would be:

http://localhost:9009/shasta/32/original/002.jpg

And even more importantly, they can be referred to relatively even without the scheme and host.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK