Giter Site home page Giter Site logo

Comments (2)

fi3ework avatar fi3ework commented on August 17, 2024 2

Here's the correct config as documented (https://github.com/rspack-contrib/storybook-rsbuild#error-caused-by-bundling-unexpected-files). source.exclude won't work here, as it's only for jsx|tsx files, it still lacks loaders for txt and ps files. We will support webpackInclude magic comment for Rspack to resolve this issue in the future.

import type { StorybookConfig } from 'storybook-react-rsbuild'
import { join, dirname, extname } from 'path'
import { mergeRsbuildConfig } from '@rsbuild/core'

/**
 * This function is used to resolve the absolute path of a package.
 * It is needed in projects that use Yarn PnP or are set up within a monorepo.
 */
function getAbsolutePath(value: string): any {
  return dirname(require.resolve(join(value, 'package.json')))
}

const config: StorybookConfig = {
  stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
  addons: [
    getAbsolutePath('@storybook/addon-onboarding'),
    getAbsolutePath('@storybook/addon-links'),
    getAbsolutePath('@storybook/addon-essentials'),
    getAbsolutePath('@chromatic-com/storybook'),
    getAbsolutePath('@storybook/addon-interactions'),
  ],
  framework: {
    name: getAbsolutePath('storybook-react-rsbuild'),
    options: {},
  },
  docs: {
    autodocs: 'tag',
  },
  rsbuildFinal: (config) => {
    if (!config.source) {
      config.source = {}
    }

    return mergeRsbuildConfig(config, {
      tools: {
        rspack: (config, { addRules, appendPlugins, rspack, mergeConfig }) => {
          return mergeConfig(config, {
            plugins: [
              new rspack.IgnorePlugin({
                checkResource: (resource, context) => {
                  // for example, ignore all markdown files
                  const absPathHasExt = extname(resource)
                  if (absPathHasExt === '.txt' || absPathHasExt === '.ps1') {
                    return true
                  }

                  return false
                },
              }),
            ],
          })
        },
      },
    })

    return config
  },
  typescript: {
    reactDocgen: 'react-docgen',
    check: true,
  },
}

export default config

from storybook-rsbuild.

NajamShehzad avatar NajamShehzad commented on August 17, 2024

Here's the link of example repo: https://github.com/NajamShehzad/storybook-rsbuild

from storybook-rsbuild.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.