storybook-css-modules

1.0.0 • Public • Published

Storybook CSS Modules preset · npm package

Storybook preset addon to add CSS Modules capabilities


Installation

npm install -D storybook-css-modules

Basic usage

Next, update .storybook/main.js to the following:

// .storybook/main.js

module.exports = {
  stories: [
    // ...
  ],
  addons: [
    // Other Storybook addons

    "storybook-css-modules", // 👈 The addon registered here
  ],
};

By default this preset configured CSS Modules with this options:

{
  "importLoaders": 1,
  "modules": {
    "localIdentName": "[path][name]__[local]--[hash:base64:5]"
  }
}

If you need specific different options, override this in .storybook/main.js using cssModulesLoaderOptions, example:

// .storybook/main.js

const { getLocalIdentName } = require("css-loader-shorter-classnames");
const getLocalIdent = getLocalIdentName();

module.exports = {
  stories: [
    // ...
  ],
  addons: [
    // Other Storybook addons

    {
      name: "storybook-css-modules",
      options: {
        cssModulesLoaderOptions: {
          importLoaders: 1,
          modules: {
            getLocalIdent,
          },
        },
      },
    },
  ],
};

Package Sidebar

Install

npm i storybook-css-modules@1.0.0

Version

1.0.0

License

MIT

Unpacked Size

9.07 kB

Total Files

4

Last publish

Collaborators

  • prototypa