Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS imported assets are bundled twice #66

Closed
Atmos4 opened this issue Aug 12, 2024 · 3 comments · Fixed by #69
Closed

CSS imported assets are bundled twice #66

Atmos4 opened this issue Aug 12, 2024 · 3 comments · Fixed by #69
Labels
bug Something isn't working

Comments

@Atmos4
Copy link

Atmos4 commented Aug 12, 2024

When importing assets in CSS, it gets bundled twice (once by Storybook and once by rsbuild) resulting in broken URLs.

Example repo: https://github.com/Atmos4/rsbuild-storybook-demo/tree/wrong-asset-import
Branch: wrong-asset-import

Example CSS:

.asset-in-css::after {
  content: url("./assets/context.png");
  width: 10px;
  height: 10px;
}

Resulting in the following URL: /static/css/async/static/image/static/media/src/stories/assets/context.png.
The correct URL (that resolves to something) is: /static/image/static/media/src/stories/assets/context.png

Expected behavior:

Storybook should ignore those assets. Maybe there is a configuration option I can tweak to make storybook ignore these CSS assets, I am not sure.

@Atmos4
Copy link
Author

Atmos4 commented Aug 12, 2024

I managed to find similar issues related to custom webpack configurations: https://stackoverflow.com/questions/66410246/how-can-i-use-static-assets-on-scss-with-storybook

It seems like if static assets are in a nested directory, Storybook cannot resolve them properly. Therefore my temporary solution is to change the rsbuildFinal to this:

const config: StorybookConfig = {
	rsbuildFinal: config => {
		config.output ||= {};
		config.output.distPath = {
			root: "/",
			image: "/",
			font: "/",
			css: "/",
			cssAsync: "/",
			svg: "/",
		};
		return config;
	},
};

It works, but it's not pretty. I wonder if there is a better fix 🤔

@fi3ework
Copy link
Member

Thank you for the detailed issue report. I checked the repository and was able to reproduce the problem. How did you determine that this issue is caused by Storybook being bundled twice? Could you provide some clues for troubleshooting?

@fi3ework fi3ework added the bug Something isn't working label Aug 12, 2024
@Atmos4
Copy link
Author

Atmos4 commented Aug 12, 2024

Now I am not really sure that is the case anymore

The reason why I was thinking that is because the URL clearly looks to be formed like this:
storybook static asset path + rsbuild bundled asset

But it might just be that storybook just can't resolve assets with nested paths and defaults to putting it in its default asset directory 🤔 I am not really sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants