Skip to content

Commit

Permalink
fix: do not use relative path in html (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework authored Sep 3, 2024
1 parent 17d28d2 commit 3d24b03
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 16 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,24 @@ The `configType` variable will be either `"DEVELOPMENT"` or `"PRODUCTION"`.

The function should return the updated Rsbuild configuration.

## Troubleshooting
## FAQ

### How to Storybook to a subdirectory / subpath?

The default Vite and webpack builders in Storybook use relative paths for references, whereas Rsbuild does not recommend using relative paths for deployment (See the [tips](https://rsbuild.dev/config/output/asset-prefix#path-types:~:text=on%20file%20location.-,TIP,-It%27s%20not%20recommended)). Therefore, if you want to deploy Storybook on a sub-path such as `https://example.com/sb-path`, you can achieve this by configuring [`output.assetPrefix`](https://rsbuild.dev/config/output/asset-prefix).

```diff
const config: StorybookConfig = {
// --snip--
rsbuildFinal: (config) => {
+ config.output ??= {}
+ config.output.assetPrefix = '/sb-path/'
return config
},
// --snip--
}
```


### Error caused by bundling unexpected files

Expand Down
5 changes: 5 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"semicolons": "asNeeded"
}
},
"css": {
"formatter": {
"enabled": true
}
},
"linter": {
"enabled": true,
"ignore": ["./scripts/"],
Expand Down
7 changes: 1 addition & 6 deletions packages/builder-rsbuild/templates/preview.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,8 @@
<% } %>
<script type="module">
import './sb-preview/runtime.js';
<% htmlWebpackPlugin.files.js.forEach(file => { %>
<% if (file.startsWith('/')) { %>
import '.<%= file %>';
<% } else { %>
import './<%= file %>';
<% } %>
import '<%= file %>';
<% }); %>
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion sandboxes/react-16/src/stories/button.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.storybook-button {
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-family: "Nunito Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 700;
border: 0;
border-radius: 3em;
Expand Down
2 changes: 1 addition & 1 deletion sandboxes/react-16/src/stories/header.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.storybook-header {
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-family: "Nunito Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
padding: 15px 20px;
display: flex;
Expand Down
2 changes: 1 addition & 1 deletion sandboxes/react-16/src/stories/page.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.storybook-page {
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-family: "Nunito Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 24px;
padding: 48px 20px;
Expand Down
2 changes: 1 addition & 1 deletion sandboxes/react-18/src/stories/button.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.storybook-button {
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-family: "Nunito Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 700;
border: 0;
border-radius: 3em;
Expand Down
2 changes: 1 addition & 1 deletion sandboxes/react-18/src/stories/header.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.storybook-header {
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-family: "Nunito Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
padding: 15px 20px;
display: flex;
Expand Down
6 changes: 5 additions & 1 deletion sandboxes/react-18/src/stories/page.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.storybook-page {
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-family: "Nunito Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 24px;
padding: 48px 20px;
Expand All @@ -17,6 +17,10 @@
vertical-align: top;
}

.storybook-page h2::before {
content: url("./assets/context.png");
}

.storybook-page p {
margin: 1em 0;
}
Expand Down
2 changes: 1 addition & 1 deletion sandboxes/vue3/src/stories/button.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.storybook-button {
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-family: "Nunito Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 700;
border: 0;
border-radius: 3em;
Expand Down
2 changes: 1 addition & 1 deletion sandboxes/vue3/src/stories/header.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.storybook-header {
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-family: "Nunito Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
padding: 15px 20px;
display: flex;
Expand Down
2 changes: 1 addition & 1 deletion sandboxes/vue3/src/stories/page.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.storybook-page {
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-family: "Nunito Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 24px;
padding: 48px 20px;
Expand Down

0 comments on commit 3d24b03

Please sign in to comment.