源代码

显示当前故事的源代码示例

在 Github 上查看

@mihkeleidast/storybook-addon-source

安装

首先,安装软件包。

npm install --save-dev @mihkeleidast/storybook-addon-source

然后,在 .storybook/main.js 中将其注册为插件。

// .storybook/main.ts

// Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
import type { StorybookConfig } from '@storybook/your-framework';

const config: StorybookConfig = {
  // ...rest of config
  addons: [
    '@storybook/addon-essentials'
    '@mihkeleidast/storybook-addon-source', // 👈 register the addon here
  ],
};

export default config;

然后,在 .storybook/preview.js 中添加装饰器。

// .storybook/preview.ts
import { Preview } from "@storybook/react";

import { withJsx } from '../dist/index.js'

const preview: Preview = {
  decorators: [
    withJsx, // 👈 add the decorator as the first one
    // ... rest of decorators
  ],
};

export default preview;
作者
  • mihkeleidast
    mihkeleidast
适用于
    React
标签