Coder Social home page Coder Social logo

rspack-contrib / storybook-rsbuild Goto Github PK

View Code? Open in Web Editor NEW
48.0 5.0 1.0 1.7 MB

Storybook builder powered by Rsbuild.

License: MIT License

TypeScript 63.39% EJS 1.79% Handlebars 1.10% JavaScript 0.30% CSS 7.20% MDX 20.60% Vue 5.62%
react rsbuild rspack storybook vue

storybook-rsbuild's Introduction

Storybook ร— Rsbuild

Storybook Rsbuild

The repository contains the Storybook Rsbuild builder and framework integrations for UI frameworks.

package description
storybook-builder-rsbuild Rsbuild powered builder for Storybook
storybook-react-rsbuild React integration for Storybook with Rsbuild builder
storybook-vue3-rsbuild Vue3 integration for Storybook with Rsbuild builder

Usage

Note

Requirements: @rsbuild/core >= 0.6.15 and storybook >= 8.0 (checkout Storybook's release note for migration)

In Storybook v8, you don't need to manually install storybook-builder-rsbuild, it has been depended by the framework, such as storybook-react-rsbuild and storybook-vue3-rsbuild.

Use with React

  1. Install React framework integration

    pnpm i storybook-react-rsbuild -D
  2. Change .storybook/main.js

    import { StorybookConfig } from 'storybook-react-rsbuild'
    
    const config: StorybookConfig = {
      framework: 'storybook-react-rsbuild',
      rsbuildFinal: (config) => {
        // Customize the final Rsbuild config here
        return config;
      },
    };
    
    export default config;

You're all set now. You could also checkout the example in sandboxes/react-rsbuild.

Use with Vue3

  1. Install Vue3 framework integration

    pnpm i storybook-vue3-rsbuild -D
  2. Change .storybook/main.js

    import { StorybookConfig } from 'storybook-vue3-rsbuild'
    
    const config: StorybookConfig = {
      framework: 'storybook-vue3-rsbuild',
      rsbuildFinal: (config) => {
        // Customize the final Rsbuild config here
        return config;
      },
    };
    
    export default config;

You're all set now. You could also checkout the example in sandboxes/vue3-rsbuild.

Customize the Rsbuild config

The builder will read your rsbuild.config.js file, though it may change some of the options in order to work correctly. It looks for the Rsbuild config in the CWD. If your config is located elsewhere, specify the path using the rsbuildConfigPath builder option:

// .storybook/main.mjs

const config = {
  framework: {
    name: 'storybook-react-rsbuild',
    options: {
      builder: {
        rsbuildConfigPath: '.storybook/customRsbuildConfig.js',
      },
    },
  },
}

export default config

You can also override the merged Rsbuild config:

// use `mergeRsbuildConfig` to recursively merge Rsbuild options
import { mergeRsbuildConfig } from '@rsbuild/core'

const config = {
  async rsbuildFinal(config, { configType }) {
    // Be sure to return the customized config
    return mergeRsbuildConfig(config, {
      // Customize the Rsbuild config for Storybook
      source: {
        alias: { foo: 'bar' },
      },
    })
  },
}

export default config

The rsbuildFinal function will give you config which is the combination of your project's Rsbuild config and the builder's own Rsbuild config. You can tweak this as you want, for example to set up aliases, add new plugins etc.

The configType variable will be either "DEVELOPMENT" or "PRODUCTION".

The function should return the updated Rsbuild configuration.

Troubleshooting

Error caused by bundling unexpected files

Because Rspack temporarily does not support the webpackInclude magic comment, non-story files may be bundled, which could lead to build failures. These files can be ignored using rspack.IgnorePlugin (see exmaple #19).

// .storybook/main.js
import path from 'path'
import { mergeRsbuildConfig } from '@rsbuild/core'

export default {
  framework: 'storybook-react-rsbuild',
  async rsbuildFinal(config) {
    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 = path.extname(resource)
                  if (absPathHasExt === '.md') {
                    return true
                  }

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

Roadmap

Features

  • Support TS type check (fork-ts-checker-webpack-plugin)
  • Support more frameworks (Preact / Svelte / vanilla html / Lit)

Rspack support

  • Support webpackInclude magic comment ๐ŸŒŸ
  • Support persistent cache
  • Support lazy compilation
  • Support virtual modules
  • Support module.unknownContextCritical
  • Support compilation.dependencyTemplates.set for react-docgen-typescript ๐ŸŒŸ

Credits

Some code is copied or modified from storybookjs/storybook.

License

MIT

storybook-rsbuild's People

Contributors

chenjiahan avatar fi3ework avatar valentinpalkovic avatar wrose504 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

storybook-rsbuild's Issues

Parsing non TS/JS files giving error

I encountered an issue while working with the project where non-JavaScript or TypeScript files are being parsed, leading to errors.
Here are the details:

File: C:\Users\Admin\Desktop\WorkingFiles\react-rsbuild\src\tools\generate-components-output-file\windws.ps1:1:1

  ร— Module parse failed:
  โ•ฐโ”€โ–ถ   ร— JavaScript parsing error: Expected ';', '}' or <eof>
         โ•ญโ”€[1:1]
       1 โ”‚ $rootPath = "test_root_path" # Set your components root folder path here
         ยท                              โ”€
       2 โ”‚ $outputFile = "test_root_path" # Set your output file path here
         โ•ฐโ”€โ”€โ”€โ”€
  help:
        You may need an appropriate loader to handle this file type.

It tries to parse all files, including PDFs, text files, and PS1 scripts, within the src folder. I also tried to exclude the tools folder, but it still attempts to parse these files.

image

I'm not even using these files in the code but they still get pick up and being process

Unable to get storybook to build with storybook-rsbuild.

Hi,

Since adding storybook-rsbuild, I've found that I'm unable to get a build to complete.

The process always gets stuck on:

โ— Client โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” (70%) sealing chunk optimization

If I run it in dev mode, the iframe.html never loads - and sits in pending.

The UI shows:

start   Compiling...

The full output, for build:

$ yarn run build:storybook
@storybook/cli v7.6.19

info => Cleaning outputDir: /.storybook/dist
info => Loading presets
info => Building manager..
info => Manager built (582 ms)
info => Building preview..
info Addon-docs: using MDX3
info => Copying static files: /Users/ed.hartwellgoose/my-company/node_modules/@storybook/manager/static at /Users/ed.hartwellgoose/my-company/frontend/.storybook/dist/sb-common-assets
warn    Rsbuild plugin "rsbuild:less" registered multiple times.
โ— Client โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” (70%) sealing chunk optimization

For dev:

$ yarn run storybook
Initializing the Mock Service Worker at "/Users/ed.hartwellgoose/my-company/frontend/.storybook/dist"...

Service Worker successfully created!
/Users/ed.hartwellgoose/my-company/frontend/.storybook/dist/mockServiceWorker.js

Continue by creating a mocking definition module in your application:

https://mswjs.io/docs/getting-started/mocks

@storybook/cli v7.6.19

info => Serving static files from ././.storybook/dist at /
info => Starting manager..
info => Starting preview..
info Addon-docs: using MDX3
warn    Rsbuild plugin "rsbuild:less" registered multiple times.
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚                                                                                                         โ”‚
โ”‚   Storybook 7.6.19 for /Users/ed.hartwellgoose/my-company/node_modules/storybook-react-rsbuild started   โ”‚
โ”‚   1.18 s for manager and 1.61 s for preview                                                             โ”‚
โ”‚                                                                                                         โ”‚
โ”‚    Local:            https://localhost:8082/                                                            โ”‚
โ”‚    On your network:  https://my-company.dev:8082/                                                        โ”‚
โ”‚                                                                                                         โ”‚
โ”‚   A new version (8.1.6) is available!                                                                   โ”‚
โ”‚                                                                                                         โ”‚
โ”‚   Upgrade now: npx storybook@latest upgrade                                                             โ”‚
โ”‚                                                                                                         โ”‚
โ”‚   Read full changelog: https://github.com/storybookjs/storybook/blob/next/CHANGELOG.md                  โ”‚
โ”‚                                                                                                         โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
start   Compiling...

The terminal looks like it's running esbuild when it gets stuck.

I've tried running with various debug options, e.g. --debug or --loglevel silly, but it provides nothing new which puzzles me.

Any clues or points as to what might be the issue? Or what information would help with debugging?

Thanks,
Ed

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.