npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@unional/preset-create-react-app

v3.2.1

Published

Create React App preset for Storybook

Downloads

3

Readme

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

Note: you don't need to do this manually if you used npx -p @storybook/cli sb init on a create-react-app, everything should properly setup already ✅.

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