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

emp-storybook-cli

v1.0.20

Published

> 0 配置 Storybook React 组件库 CLI

Downloads

8

Readme

emp-storybook-cli

0 配置 Storybook React 组件库 CLI

使用

安装

  1. 安装 CLI
yarn add emp-storybook-cli -D
  1. 创建 *.stories.tsx, 即可为你组件创建 storybook 文档!

默认匹配目录:root_dir/src或者root_dir/stories,可通过storybook.config.js覆盖配置

  1. package.json中添加对应 script
{
  "scripts": {
    "docs:dev": "emp-storybook dev",
    "docs:build": "emp-storybook build"
  }
}
  1. 执行 cli
# 开发
yarn docs:dev
# 构建
yarn docs:build

自定义 Storybook 配置

在项目根目录新建storybook.config.js,相关配置项见如下注释

const {EmpStorybookCli} = require('emp-storybook-cli')
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");

/**
 * @type {EmpStorybookCli}
 */
module.exports = {
  // custom storybook config: https://storybook.js.org/docs/react/configure/overview
  storybook: {
    // override your storybook config, auto detect base on your project rootpath
    stories: ['./src/**/*.stories.@(jsx|tsx)']
  },
  // custom preview webpack config
  previewWebpack: (config) => {
    config.plugins.push(new ModuleFederationPlugin({...}))
    return config
  },
  // custom manager webpack config
  managerWebpack: config => config,
  // https://storybook.js.org/docs/react/configure/theming
  theme: {
    // auto get description/name in package.json, or custom by brandTitle
    brandTitle: 'EMP组件库',
    // 'light' | 'dark'
    theme: 'light'
  },
  // https://storybook.js.org/docs/react/configure/features-and-behavior
  addons: {}
}

注意事项

关于 webpack5

如果你的项目不基于 webpack 构建,可忽略以下事项

如果你项目中依赖有 webpack,请确保支持webpack > 5,并且请在项目中使用yarn resolutions锁定 webpack 和相关插件的版本,防止与现有版本冲突导致构建失败。

拷贝如下代码到package.json即可。

{
  "resolutions": {
    "webpack": "^5.0.0",
    "css-loader": "^5.0.0",
    "dotenv-webpack": "^6.0.0",
    "html-webpack-plugin": "^5.0.0",
    "style-loader": "^2.0.0",
    "terser-webpack-plugin": "^5.0.0",
    "webpack-dev-middleware": "^4.1.0",
    "webpack-virtual-modules": "^0.4.2",
    "mini-css-extract-plugin": "^0.9.0"
  }
}

已知问题

  1. webpack5 模式下,storybook 仍不支持 remotes 包,由于源码仍未兼容 bootstrap 写法, 详见 https://github.com/storybookjs/storybook/issues/15177