@storybook/preset-create-react-app
Create React App preset for Storybook
Last updated 4 months ago by shilman .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @storybook/preset-create-react-app 
SYNC missed versions from official npm registry.

Create React App preset for Storybook

One-line Create React App configuration for Storybook.

This preset is designed to use alongside @storybook/react.

Basic usage

First, install this preset to your project.

# Yarn
yarn add -D @storybook/preset-create-react-app

# npm
npm install -D @storybook/preset-create-react-app

Once installed, add this preset to the appropriate file:

  • ./.storybook/main.js (for Storybook 5.3.0 and newer)

    module.exports = {
      addons: ['@storybook/preset-create-react-app'],
    };
    
  • ./.storybook/presets.js (for all Storybook versions)

    module.exports = ['@storybook/preset-create-react-app'];
    

Advanced usage

Usage with Docs

When working with Storybook Docs, simply add the following config to your main.js file.

module.exports = {
  addons: [
    '@storybook/preset-create-react-app',
    {
      name: '@storybook/addon-docs',
      options: {
        configureJSX: true,
      },
    },
  ],
};

CRA overrides

This preset uses CRA's Webpack/Babel configurations, so that Storybook's behavior matches your app's behavior.

However, there may be some cases where you'd rather override CRA's default behavior. If that is something you need, you can use the craOverrides object.

Option Default Behaviour Type Description
fileLoaderExcludes ['ejs', 'mdx'] Extends string[] Excludes file types (by extension) from CRA's file-loader configuration. The defaults are required by Storybook.

Here's how you might configure this preset to ignore PDF files so they can be processed by another preset or loader:

module.exports = {
  addons: [
    {
      name: '@storybook/preset-create-react-app',
      options: {
        craOverrides: {
          fileLoaderExcludes: ['pdf'],
        },
      },
    },
  ],
};

Custom react-scripts packages

In most cases, this preset will find your react-scripts package, even if it's a fork of the offical react-scripts.

In the event that it doesn't, you can set the package's name with scriptsPackageName.

module.exports = {
  addons: [
    {
      name: '@storybook/preset-create-react-app',
      options: {
        scriptsPackageName: '@my/react-scripts',
      },
    },
  ],
};

Warning for forks of 'react-scripts'

One of the tasks that this preset does is inject the storybook config directory (the default is .storybook) into the includes key of the webpack babel-loader config that react-scripts (or your fork) provides. This is nice because then any components/code you've defined in your storybook config directory will be run through the babel-loader as well.

The potential gotcha exists if you have tweaked the Conditions of the webpack babel-loader rule in your fork of react-scripts. This preset will make the include condition an array (if not already), and inject the storybook config directory. If you have changed the conditions to utilize an exclude, then BOTH conditions will need to be true (which isn't likely going to work as expected).

The steps to remedy this would be to follow the steps for customizing the webpack config within the storybook side of things. Details for storybook custom webpack config You'll have access to all of the rules in config.module.rules. You'll need to find the offending rule, and customize it how you need it to be to be compatible with your fork.

See Webpack Rule Conditions for more details concerning the conditions.

Resources

Current Tags

  • 3.1.4                                ...           latest (4 months ago)

25 Versions

  • 3.1.4                                ...           4 months ago
  • 3.1.3                                ...           4 months ago
  • 3.1.2                                ...           4 months ago
  • 3.1.1                                ...           4 months ago
  • 3.1.0                                ...           4 months ago
  • 3.0.1                                ...           5 months ago
  • 3.0.0                                ...           5 months ago
  • 2.1.2                                ...           6 months ago
  • 2.1.1                                ...           7 months ago
  • 2.1.0                                ...           7 months ago
  • 2.0.0                                ...           8 months ago
  • 1.5.2                                ...           9 months ago
  • 1.5.1                                ...           10 months ago
  • 1.5.0                                ...           10 months ago
  • 1.4.0                                ...           10 months ago
  • 1.3.2                                ...           a year ago
  • 1.3.1                                ...           a year ago
  • 1.3.0                                ...           a year ago
  • 1.2.0                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
  • 1.0.0-beta.3                                ...           a year ago
  • 1.0.0-beta.2                                ...           a year ago
  • 1.0.0-beta.1                                ...           a year ago

Copyright 2014 - 2016 © taobao.org |