question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No global style in Storybook with Angular 12

See original GitHub issue

Current Behavior

The global style is not applied in Storybook.

It has been added in preview.js as follows:

import '!style-loader!css-loader!sass-loader!../../../apps/client/src/styles.scss';

Expected Behavior

The global style gets applied to each Storybook story.

Steps to Reproduce

  1. Clone https://github.com/ghostfolio/ghostfolio
  2. Install dependencies: yarn install
  3. Start Storybook: yarn start:storybook
  4. Open http://localhost:4400/?path=/story/value--currency
  5. E.g. d-flex (utility class from Bootstrap) is not applied

Environment

  Node : 16.6.2
  OS   : darwin x64
  yarn : 1.22.5
  
  nx : 12.9.0
  @nrwl/angular : 12.8.0
  @nrwl/cli : 12.8.0
  @nrwl/cypress : 12.8.0
  @nrwl/devkit : 12.8.0
  @nrwl/eslint-plugin-nx : 12.8.0
  @nrwl/jest : 12.8.0
  @nrwl/linter : 12.8.0
  @nrwl/nest : 12.8.0
  @nrwl/node : 12.8.0
  @nrwl/tao : 12.8.0
  @nrwl/workspace : 12.8.0
  @nrwl/storybook : 12.9.0
  typescript : 4.3.5

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:9
  • Comments:21 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
Sjeiticommented, Feb 9, 2022

Hi there @itayod! Can you please take a look at this comment here

That didn’t work entirely but did point me in the right direction to configure styles in two places:

nx storybook ... uses projects.[project].architect.storybook.options.styles

nx e2e ... uses projects.[project].architect.build-storybook.options.styles

(it’s a pity that an import in preview.js never worked; angular.json is the wrong place for this imho)

5reactions
junekpavelcommented, Feb 20, 2022

Hey you all! I spend an eternity trying to fix this issue.

In my case, the problem was that the targets (storybook and build-storybook) were generated (by nx) with wrong configuration.

I generated it via the nx g @nrwl/angular:storybook-configuration my-lib command, and the generated targets looked like this. Notice the projectBuildConfig:

  "storybook": {
      "executor": "@nrwl/storybook:storybook",
      "options": {
        "uiFramework": "@storybook/angular",
        "port": 4400,
        "config": {
          "configFolder": "libs/my/lib/.storybook"
        },
        "projectBuildConfig": "my-lib"
      },
      "configurations": {
        "ci": {
          "quiet": true
        }
      }
    },
    "build-storybook": {
      "executor": "@nrwl/storybook:build",
      "outputs": ["{options.outputPath}"],
      "options": {
        "uiFramework": "@storybook/angular",
        "outputPath": "dist/storybook/my/lib",
        "config": {
          "configFolder": "libs/my/lib/.storybook"
        },
        "projectBuildConfig": "ui-tables"
      },
      "configurations": {
        "ci": {
          "quiet": true
        }
      }
    }

I had to manually update the projectBuildConfig option to look like this - "projectBuildConfig": "my-lib:build-storybook".

Now my complete configuration looks like this:

"storybook": {
      "executor": "@nrwl/storybook:storybook",
      "options": {
        "uiFramework": "@storybook/angular",
        "port": 4400,
        "config": {
          "configFolder": "libs/my/lib/.storybook"
        },
        "projectBuildConfig": "my-lib:build-storybook"
      },
      "configurations": {
        "ci": {
          "quiet": true
        }
      }
    },
    "build-storybook": {
      "executor": "@nrwl/storybook:build",
      "outputs": ["{options.outputPath}"],
      "options": {
        "uiFramework": "@storybook/angular",
        "outputPath": "dist/storybook/my-lib",
        "config": {
          "configFolder": "libs/my/lib/.storybook"
        },
        "styles": [
          "./libs/xxx/yyy/assets/styles/shared.scss"
        ],
        "projectBuildConfig": "my-lib:build-storybook"
      },
      "configurations": {
        "ci": {
          "quiet": true
        }
      }
    }

Everything works as expected now.

Using @nrwl/storybook : 13.8.2.


Update: For more context, not sure if it’s relevant or not, but the library I was adding storybook configuration into, is buildable - it already had the build target (with the @nrwl/angular:ng-packagr-lite executor) when I was generating the storybook configuration.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Global SCSS style is no longer loaded in Storybook with ...
To do so, I upgraded Angular and Material to version 12 with the Angular Update Guide, Storybook to version 6.3 with npx sb...
Read more >
6 Ways To Configure Global Styles for Storybook | by Jennifer Fu
It is a common task to configure global styles for Storybook, such as background color, color, font family, and font sizes. In this...
Read more >
Reopened bug. Angular 13. Global styles no longer work in ...
Global styles no longer work in SB 6.4 (CSS or SCSS) #16950 ... a NX issue or Storybook issue, but I am sure...
Read more >
Storybook Addon Next
Next.js Routing. Overriding defaults; Global Defaults; Default Router; Actions Integration Caveats. Sass/Scss; Css/Sass/Scss Modules; Styled JSX; Postcss ...
Read more >
Import Your Angular Scss Files in Storybook | Bits && Pixels
How to deal with styles from global/external *.scss files when ... when Angular 13 came out and I could not get gobal styles...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found