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

storybook: loading shared styles with sass-loader is broken #8882

Closed
gkamperis opened this issue Feb 7, 2022 · 9 comments
Closed

storybook: loading shared styles with sass-loader is broken #8882

gkamperis opened this issue Feb 7, 2022 · 9 comments
Assignees
Labels
outdated scope: storybook Issues related to Storybook support in Nx type: bug

Comments

@gkamperis
Copy link

gkamperis commented Feb 7, 2022

Current Behavior

Importing shared scss into a Storybook via

// preview.js 
// tried both in the lib's .storybook and the main repo top-level .storybook (neither work)
import "!style-loader!css-loader!sass-loader!../src/styles/styles.scss";

is not working via Nx.

NOTE: It is working with the standard Storybook setup following
https://storybook.js.org/tutorials/intro-to-storybook/angular/en/get-started/
and adding custom "shared" scss

Expected Behavior

Expect this to work as per default Storybook - was also working in the past...

Steps to Reproduce

Create an Nx workspace with shared styles as per Nx example repo.
https://github.com/nrwl/nx-examples

Import the shared styles via

// preview.js
import "!style-loader!css-loader!sass-loader!../src/styles/styles.scss";

Another report of the same issue here
#7613 (comment)

Failure Logs

No logs are created.

Environment

Nx 13.7.3
Angular 13.2.1
@storybook-angular 6.4.18

@gkamperis gkamperis changed the title storybook: loading shared styles into with sass-loader is broken storybook: loading shared styles with sass-loader is broken Feb 7, 2022
@mandarini mandarini added the scope: storybook Issues related to Storybook support in Nx label Feb 7, 2022
@mandarini
Copy link
Member

mandarini commented Feb 7, 2022

Hi there @gkamperis ! Thanks for filing an issue!

Can you let me know if this comment helps? Also, if any of these issues help:

#8790
#8772
#8681
#8580
#8360

@mandarini
Copy link
Member

Also, please take a look at this comment in this issue here. That is, you can use a format like this in your project:

    "build-storybook": {
      "executor": "@nrwl/storybook:build",
      "options": {
        "uiFramework": "@storybook/angular",
         ...
        "projectBuildConfig": "<YOUR-LIB-NAME>:build-storybook",
        "stylePreprocessorOptions": {
          "includePaths": ["SOME-PATH", "EG. OTHER PATH: node_modules/@angular/flex-layout/core/sass"]
        }
      },
    ...
    },

@mandarini mandarini self-assigned this Feb 7, 2022
@gkamperis
Copy link
Author

Hello @mandarini

thanks for the quick response.

"stylePreprocessorOptions": {
          "includePaths": ["SOME-PATH", "EG. OTHER PATH: node_modules/@angular/flex-layout/core/sass"]
        }

seems to have no effect.

"styles": ["path/to/style.scss"]

seems to work but... it is different to
import "!style-loader!css-loader!sass-loader!../src/styles/styles.scss";

for example it does not load svgs...
in our style.scss we reference @import 'node_modules/@fortawesome/fontawesome-free/scss/solid';

with sass-loader we compile correctly.

with styles the build breaks as it mixes up the location of the svg paths and tries to locate them under my styles path vs node_modules/@fortawesome

Any ideas on how to get around this?

Thanks

@gkamperis
Copy link
Author

@mandarini wow this is mind-boggling!

// file: path/to/style.scss

@import 'node_modules/@fortawesome/fontawesome-free/scss/solid';

// file: angular.json
// under storybook configs

"styles": ["path/to/style.scss"]

breaks with svgs not found as mentioned in the previous comment confusing the paths (node_modules vs shared/style/paths).

But... if I just rename the file and update the config accordingly...

styles.scss to styles2.scss

it works! svgs are resolved correctly no compilation error and icons shown correctly!

@gkamperis
Copy link
Author

@mandarini I figured it out....

turns out... I forgot to remove

import "!style-loader!css-loader!sass-loader!../src/styles/styles.scss";

and that was somehow causing issues.

once removed styles.scss in angular.json is ok...

On a final note... it would be good to update the docs with the styles property as well - and any other ones supported... :)

https://nx.dev/storybook/overview-angular#setting-up-projectbuildconfig

Pls feel free to close this issue.

Thanks!

@mandarini
Copy link
Member

mandarini commented Feb 8, 2022

Yes, updating the docs is in the roadmap! :) Thank you!

klingebiel added a commit to e-Learning-by-SSE/stu-mgmt-web-client that referenced this issue Feb 9, 2022
See nrwl/nx#8790 and nrwl/nx#8882 for information about storybook config changes.
@mandarini
Copy link
Member

New docs for styles and stylePreprocessorOptions

@gkamperis
Copy link
Author

@mandarini amazing! thanks for all your help!

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: storybook Issues related to Storybook support in Nx type: bug
Projects
None yet
Development

No branches or pull requests

2 participants