CleverCloud / clever-components

Collection of Web Components by Clever Cloud
https://www.clever-cloud.com/doc/clever-components/
Apache License 2.0
220 stars 19 forks source link

Storybook: fix build path & docs URLs #974

Closed florian-sanders-cc closed 7 months ago

florian-sanders-cc commented 7 months ago

Context

Build output folder

In #952, I forgot that I had hard coded where storybook should be built.

This means storybook is always built inside a storybook-static folder.

This works well for previews and dev but it does not work for our production app.

More info about the output folder issue Our production app is set to only handle requests from: `https://[www.]clever-cloud.com/doc/clever-components/`. In other words, we rely on [prefix routing](https://developers.clever-cloud.com/doc/administrate/domain-names/#prefix-routing). For this to work correctly on the Clever Cloud side, the app must contain a folder corresponding to the path we have defined (the part after the domain in the example above). That is to say: `/doc/clever-components/` This is why we had the following command before the upgrade: `build-storybook -o storybook-static${STORYBOOK_PATH}` The `${STORYBOOK_PATH}` refers to an env variable that is set on our production app with the following value: `/doc/clever-components/`. This means that when we build with this command, our bundle goes to the following paths: - `storybook-static/` in dev & preview because the `${STORYBOOK_PATH}` is not set, - `storybook-static/doc/clever-components/` in prod. This way when a request is made to `https://www.clever-cloud.com/doc/clever-components/`, the server is able to serve the content of the `storybook-static/doc/clever-component/` folder.

Docs URL

With the storybook upgrade, we've changed the way we handled our docs stories and we managed to make storybook treat these as docs. This means their URLs have changed. For instance, for the readme:

This PR changes the links so they work properly. Also, bear in mind that relative links are not possible, they will only work in previews & dev but not in prod because of what is decribed in the section above (Buid folder ouput): the prod app handles requests for a specific route (/doc/clever-components) and not the root path of the clever-cloud.com domain.

github-actions[bot] commented 7 months ago

🔎 A preview has been automatically published : https://clever-components-preview.cellar-c2.services.clever-cloud.com/storybook/fix-build-path-for-prod/index.html.

This preview will be deleted once this PR is closed.

github-actions[bot] commented 7 months ago

🔎 The preview has been automatically deleted.