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
Angular: global style entry points are bundled into JS instead of separate CSS files #15351
Comments
@shilman You have removed bug and added support, so does that mean you are saying this is the intended behaviour and storybook is intentionally overriding angular CLI’s standard behaviour? |
This needs some discussion before we agree it's a bug -- for now it seems more like a question to me. @ThibaudAV @kroeder any thoughts? Happy to call it a bug once we've confirmed it. |
I want to help you to find a solution, but I don't understand very well 😁 How do you handle the change of theme? If you have several themes and only one project with angular |
@ThibaudAV Allow me to break it all down, hopefully that will help: How and why the Angular CLI build piece works
Here is an anonymized example of real configuration:
This is exactly what we want.
Relevance and issue with Storybook
Hopefully everything is clear now, please let me know if not. If we can adjust the logic within Storybook Angular so that it stops overriding the Angular CLI's webpack config in this regard then this issue will be resolved. |
Top ! I understand much better 👍 For another topic I have slightly detailed the logic of angular here Indeed. I don't know if it's a bug or a missing feature ^^ Storybook uses some angular.json part read by some part of angular-cli code. But not complete only what it needs to complete a global webpack configuration. I think this is an unplanned case 🤷♂️ One more question ^^Why add all the styles of your clients in the same project+configuration in angular.json? Why not either do :
In both cases you would have one build per client with directly the right style files This doesn't really solve the problem unless you want to start a storybook per client 🤷♂️ Sorry I don't have perfect workaround 😞 I'll look when I have time to find what is missing in storybook to do this. But I'm worried that it's not just from the angular part ; but the behavior of storybook that wraps angular 🤷♂️ |
As @JamesHenry perfectly described, our company has a very similar use case. In |
Firstly, thanks @JamesHenry for creating this and explaining the issue very well! My team and I are facing a similar problem. @ThibaudAV, in our project, the lazy load css resolution does not happen during compilation time. We compile and deploy all the assets once. We have a ngnix router that understands the dns request and apply the tenant id as request header. Then on the app init, we resolve the tenant id by reading the header and dynamically append the appropriate css file during runtime. |
The application is functionally the same - building it multiple times (which both of these suggestions imply) is definitely not desirable even if there were only 2 clients and it were not much extra time (in our case, however, there are many more than two so from a time perspective it does not scale well at all). We should be building once, deploying N times. In our case which theme css file to package with the app is a deployment-time concern. Just to update everyone here, what I ended up doing was building a completely custom (therefore I'm afraid unshareable) Angular CLI builder/Nx executor) in order to just compile the style files using the same kind of angular-devkit webpack styles resolution which storybook does internally. I run that builder just before storybook runs and point storybook to the compiled css files as a Again, apologies I will not be able to share any of this as it is under a consultancy contract, so please don't ask 😅 FWIW @ThibaudAV, even though the type information in angular-devkit did not agree, the only significant thing I had to do on top of your existing storybook logic was to add I found this simply by looking at the angular-devkit source by seeing what it used to determine if it should produce css files or js files for styles. Hope that helps! |
We’re cleaning house! Storybook has changed a lot since this issue was created and we don’t know if it’s still valid. Please open a new issue referencing this one if:
|
Describe the bug
Honestly, this is one of those things where it seems so obviously an issue that I am half expecting you to tell me I am misunderstanding 😅
As you know, in
angular.json
you provide"styles": []
on your project - these are global entry points and when you runng build
they will be spat out as individual CSS files via the webpack build.When building storybook, however, even though I can see it is using angular devkit's webpack config for styles behind the scenes, it does not respect this and instead bundles the global CSS files into JS bundles. This is definitely not what I want.
To Reproduce
I created a brand new Nx workspace from scratch using the
angular
preset and simply added storybook, nothing else is needed: https://github.com/JamesHenry/storybook-testTo reproduce, simply compare the relevant dist entries after running
nx build
vsnx build-storybook
.System
Additional context
If you end up telling me this is the intended behaviour in storybook, then please provide some guidance on how I can work around it. I have a use-case where I very much need to spit out individual global CSS files (client-based theming).
The text was updated successfully, but these errors were encountered: