profile
viewpoint

Ask questionsError importing styles.scss to storybook

The bug I followed this tutorial in starting storybook. Though the tutorial is using less, I decided to use scss.

When I import my styles.scss into the config.js in .storybook with this configuration in webpack.config.js

const path = require("path");

module.exports = {
  module: {
    rules: [
      {
        test: /\.scss$/,
        loaders: ["style-loader", "css-loader", "sass-loader"],
        include: path.resolve(__dirname, "../")
      }
    ]
  }
};

as per https://storybook.js.org/configurations/custom-webpack-config/, it gives me an error.

If I try to change the webpack.config.js to this solution: it doesn't do anything.

Reproduce Steps to reproduce the behavior:

  1. Go to https://www.learnstorybook.com/angular/en/get-started/ and use sass styling.
  2. Continue through https://www.learnstorybook.com/angular/en/simple-component/
  3. Upon setting config.js instead of styles.less use styles.scss
  4. Upon setting webpack.config.js use this config instead:
const path = require("path");

module.exports = {
  module: {
    rules: [
      {
        test: /\.scss$/,
        loaders: ["style-loader", "css-loader", "sass-loader"],
        include: path.resolve(__dirname, "../")
      }
    ]
  }
};

from official tutorial.

And then install node-sass.

Then run npm run storybook.

Expected behavior I should be able to see styles from whatever is in styles.scss

Screenshots error1

Code snippets package.json

"dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "core-js": "^2.5.4",
    "node-sass": "^4.11.0",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "~7.3.2",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.1.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2",
    "@babel/core": "^7.3.3",
    "babel-loader": "^8.0.5",
    "@storybook/angular": "^4.1.12",
    "@storybook/addon-notes": "^4.1.12",
    "@storybook/addon-actions": "^4.1.12",
    "@storybook/addon-links": "^4.1.12",
    "@storybook/addons": "^4.1.12"
  }

config.js

import { configure } from '@storybook/angular';

import '../src/styles.scss';

// automatically import all files ending in *.stories.ts
const req = require.context('../src/stories', true, /.stories.ts$/);
function loadStories() {
  req.keys().forEach(filename => req(filename));
}

configure(loadStories, module);

webpack.config.js

const path = require("path");

module.exports = {
  module: {
    rules: [
      {
        test: /\.scss$/,
        loaders: ["style-loader", "css-loader", "sass-loader"],
        include: path.resolve(__dirname, "../")
      }
    ]
  }
};

System:

  • OS: Windows10
  • Device: Laptop
  • Browser: chrome
  • Framework: angular
  • Addons: [if relevant]
  • Version: ["@angular/core": "~7.2.0", "@storybook/angular": "^4.1.12"]

Source Code HERE.

storybookjs/storybook

Answer questions shiftgeist

@magisters-org

import '!style-loader!css-loader!sass-loader!../styles/main.scss';

This works but it outputs:

DeprecationWarning: Extend-mode configuration is deprecated, please use full-control mode instead.

See https://storybook.js.org/docs/configurations/custom-webpack-config/#full-control-mode

Here is another solution I found, because I got Invalid CSS after "": expected 1 selector or at-rule: https://github.com/storybookjs/storybook/issues/6467#issuecomment-481425563 (fix for the full-control example here)

useful!
source:https://uonfu.com/
Github User Rank List