Back to Storybook

Storybook Main Using Existing Config

docs/_snippets/storybook-main-using-existing-config.md

10.3.63.2 KB
Original Source
js
import custom from '../webpack.config.js'; // ๐Ÿ‘ˆ Custom Webpack configuration being imported.

export default {
  // Replace your-framework with the framework you are using, e.g. react-webpack5, nextjs, angular, etc.
  framework: '@storybook/your-framework',
  stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
  webpackFinal: async (config) => {
    return {
      ...config,
      module: { ...config.module, rules: [...config.module.rules, ...custom.module.rules] },
    };
  },
};
ts
// Replace your-framework with the framework you are using, e.g. react-webpack5, nextjs, angular, etc.
import type { StorybookConfig } from '@storybook/your-framework';

import custom from '../webpack.config.js'; // ๐Ÿ‘ˆ Custom Webpack configuration being imported.

const config: StorybookConfig = {
  framework: '@storybook/your-framework',
  stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
  webpackFinal: async (config) => {
    return {
      ...config,
      module: { ...config.module, rules: [...config.module.rules, ...custom.module.rules] },
    };
  },
};

export default config;
ts
// Replace your-framework with the framework you are using (e.g., react-vite, nextjs)
import { defineMain } from '@storybook/your-framework/node';

import custom from '../webpack.config.js'; // ๐Ÿ‘ˆ Custom Webpack configuration being imported.

export default defineMain({
  framework: '@storybook/your-framework',
  stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
  webpackFinal: async (config) => {
    return {
      ...config,
      module: { ...config.module, rules: [...config.module.rules, ...custom.module.rules] },
    };
  },
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
// Replace your-framework with the framework you are using (e.g., react-vite, nextjs)
import { defineMain } from '@storybook/your-framework/node';

import custom from '../webpack.config.js'; // ๐Ÿ‘ˆ Custom Webpack configuration being imported.

export default defineMain({
  framework: '@storybook/your-framework',
  stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
  webpackFinal: async (config) => {
    return {
      ...config,
      module: { ...config.module, rules: [...config.module.rules, ...custom.module.rules] },
    };
  },
});
ts
import { defineMain } from '@storybook/angular/node';

import custom from '../webpack.config.js'; // ๐Ÿ‘ˆ Custom Webpack configuration being imported.

export default defineMain({
  framework: '@storybook/angular',
  stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
  webpackFinal: async (config) => {
    return {
      ...config,
      module: { ...config.module, rules: [...config.module.rules, ...custom.module.rules] },
    };
  },
});