-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
How do I include global styles (scss) once for all Storybook iframes? #6364
Comments
Try adding your global.scss File into Check your defaultProject (there's a defaultProject property inside the json) and add it to the styles list
I do it that way and it works just fine. Is that an option for you? |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Hi @omaracrystal here is how I did it: import '!style-loader!css-loader!sass-loader!./scss-loader.scss'; Then add/import all the styles you need in the $font-path: '../projects/lib/src/theming/fonts/OpenSans/';
@import '../projects/lib/src/theming/reset.scss';
@import '../projects/lib/src/theming/main.scss';
html {
font-family: $font-name;
font-size: $font-size--small;
} The solution proposed by @kroeder works as long as your using components from an Angular application but for libraries, you cannot add the |
I did this exact thing, but it doesn't seem to load this for me when I run storybook |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook! |
Is that working for everyone ? Not working my side :( |
@ozanmanav did you try import it in PS: because for me it works but I import just |
This seems to no longer work using the main.js file structure of Storybook v5.3 |
@garrettmaring did you try with |
@garrettmaring |
@shilman yes, that did it 👍 Pretty clear once I saw some documentation on it. There might be some room for clearer docs in the main Storybook documentation. I found this article to be clear. |
@garrettmaring Mind submitting a PR to help improve the docs? |
Just some FYI that i just figured out, this approach works wonders when serving storybook locally, but it does not work (from what I saw) with build-storybook. My solution Only issue with this is when running locally, the browser console will say it cannot find If anyone has a better way of approaching this, or knows of a proper solution, let me know :) |
we serve scss files in storybook using the following: import '!style-loader!css-loader!sass-loader!./main.scss'; This works fine for us |
@blemaire Where are you using that line? |
테이블 만들다가 폰트가 안이쁘길래,... 글로벌 테마 import를 추가했다 참고 storybookjs/storybook#6364 (comment) storybookjs/storybook#6364 (comment) https://medium.com/storybookjs/declarative-storybook-configuration-49912f77b78
Thanks everyone. Confirming that
works for us; storybook i.c.w. an Angular 9 library (so no option to add it to the |
In nextjs based setup simple line of |
The above solutions works if all your pathing is relative My Not sure where to go. |
I tried this, but getting error. I need Storybook to know about my global css variables and mixins.
|
Does this styles/main.css contain your global SCSS variables? Do they get applied in Storybook at all? I tried this, but still get |
I can confirm that in the latest version 6.3 "simply" importing a css files in preview.js does not work. |
@Jordaneisenburger Do you a have a reproduction repo you can share? If not, can you create one? See how to create a repro. |
I had a problem today with styles silently failing to load with storybook 6.3 and Angular 12.2. Downgrading Angular to 12.1 fixed the issue for me. |
As @literalpie mentioned the global import of a SCSS file stooped working in Storybook 6.3.x with the version 12.2.x of Angular. |
I made a minimal reproduction and hosted on Chromatic. Steps taken to produce are in the readme.md file of the repo. https://www.chromatic.com/test?appId=6116d0fb97cb10003ce69c94&id=6116da16f8042f003aec800f |
This Works !!!! |
The issue is tracked in #15855 |
Adding my hat in the ring here. Using Vue 3.2.0 and Storybook 6.3.6, with Bootstrap 5.1, and struggling to get SCSS files working fully. Attempted:
Definitely at a loss here, very excited to see some solutions eventually, (or a Vue workaround/thread if anyone has one). |
In case anyone stumbles on this and needs it, the way I (mostly) solved my particular issue: The key for my setup was splitting my styles up properly. Making sure that styles I wanted to be injected into every component were added in main.js:
And styles/modules that only needed to be loaded once be put in preview.js:
Good luck! |
I have just resolved the issue. And you would not believe how easy it is. |
The idea is to use SASS not plain CSS, since it will require a external process in order to convert from SASS to CSS for every change in the global styling file. As the SASS file is imported and Storybook use Webpack (that basically check all the imports and create a bundle) the conversion from SASS to CSS should be handled by Webpack. |
I've following the solution by the great @proxycase with some change for a classic Vue-CLI app:
Thank you so much @proxycase , you saved my day and more than, i learn so much on this custom webpack build! |
With this setup, everything works like a charm.dependencies: "@babel/core": "^7.16.12",
"@storybook/addon-actions": "^6.4.17",
"@storybook/addon-essentials": "^6.4.17",
"@storybook/addon-links": "^6.4.17",
"@storybook/builder-webpack5": "^6.4.17",
"@storybook/manager-webpack5": "^6.4.17",
"@storybook/preset-scss": "^1.0.3",
"@storybook/react": "^6.4.17",
"@types/node": "^12.20.2",
"@types/react": "^17.0.38",
"@types/react-dom": "^17.0.11",
"babel-loader": "^8.2.3",
"css-loader": "^6.5.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"sass": "^1.49.7",
"sass-loader": "^12.4.0",
"style-loader": "^3.3.1",
"typescript": "^4.5.5",
"webpack": "^5.68.0"
const path = require('path');
module.exports = {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials', '@storybook/preset-scss'],
framework: '@storybook/react',
core: {
builder: 'webpack5',
},
};
import '../assets/stylesheets/_groupstrap.scss'; // <- this is a root stylesheet import
export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
}; Also, rather than trying to perform gradual upgrades from storybook |
This works like a charm on a brand new project for storybook |
In my Angular 13 + nx project, I'm setting up Storybook in a specific library and needed to import some third-party CSS for the Storybook app. The example in the docs worked for me:
|
I had the same problem (Storybook 6.5.9) with SCSS imports not working, while plain CSS imports worked just fine... after quite a bit of debugging, I noticed that the Webpack rule for SCSS files does not have
So the fix consists in enabling side effects for the existing SCSS rule ( const path = require('path');
module.exports = {
stories: [
'../src/**/*.stories.mdx',
'../src/**/*.stories.@(js|jsx|ts|tsx)'
],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
'@storybook/preset-scss'
],
framework: '@storybook/react',
core: {
builder: '@storybook/builder-webpack5',
disableTelemetry: true
},
webpackFinal: async (config, { configType }) => {
// Without this, the SCSS imports on preview.js are removed via tree shaking!
// By setting sideEffects to true, we disable tree shaking
// Note that for css files the config already has sideEffects set to true.
const sassRule = config.module.rules.find(rule => 'test.scss'.match(rule.test));
sassRule.sideEffects = true;
// Return the altered config
return config;
}
}; Hope this helps |
For anyone stuck with this, check out this article: |
@daniloarcidiacono Thank you for debugging that! I was struggling with the same issue and your comment helped me resolve it. I did a little more digging into See source here: https://github.com/storybookjs/presets/blob/master/packages/preset-scss/index.js#L31 // .storybook/main.js
module.exports = {
addons: [
{
name: "@storybook/preset-scss",
options: {
rule: {
sideEffects: true,
},
}
}
]
} |
JFYI: works well 💛
|
If I understand correctly we can import global SCSS styles via I tried this in an Angular 15.2 project and got the following error:
This is what the
Thoughts? |
OK For Angular 15.2 the following works:
|
Tremendous @zaur1003 ! Also works with global scss files in Next.js 13 with Storybook v7.x. My
Note it is importing another (global) scss file from within the same folder, In the code generated by A CSS module
I put
and voila, CSS definitions in the global scss file (but not SCSS features like mixins; for that you will need to My |
Here is the solution which works for me |
Describe the bug
I have been trying multiple ways of incorporating global styles (scss) once for all Storybook Iframes and have been unsuccessful. There doesn't seem to be a clear concise way to do this.
To Reproduce
Attempts:
Expected behavior
I would expect to be able to import Global (scss) files in one place so that can be applied to every Story's Iframe. Could there be a config setting I'm not aware of?
System:
Additional context
I am hoping that I am missing some configuration within storybook that would make this simple to resolve.
The text was updated successfully, but these errors were encountered: