Git Product home page Git Product logo

storybook-addon-turbo-build's Introduction

storybook-addon-turbo-build

npm npm (alpha) npm (beta) license code style: prettier

This Storybook addon improves your Storybook's build time by tweaking webpack configuration.

Improvements such as replacing Terser with ESBuild or disabling source map generation reduces your build time, so you can save your CI time or operate development cycle more quickly.

Important

Storybook already does various build performance improvements. This addon mainly improves cold build (building Storybook without cache under node_modules/.cache), you probably won't see noticable differences in cache enabled build. You should evaluate the build time before addin this addon into your workflow.

Installation

$ npm i -D storybook-addon-turbo-build

# or
$ yarn add -D storybook-addon-turbo-build

Getting Started

Add this line to your .storybook/main.js.

 module.exports = {
   stories: [
     "../stories/**/*.stories.mdx",
     "../stories/**/*.stories.@(js|jsx|ts|tsx)",
   ],
   addons: [
     "@storybook/addon-links",
     "@storybook/addon-essentials",
+    "storybook-addon-turbo-build"
   ],
 };

Configurations

You can customize modifications to webpack config through preset options.

// .storybook/main.js
module.exports = {
  // ...
  addons: [
    // ...
    {
      name: "storybook-addon-turbo-build",
      options: {
        // Please refer below tables for available options
        optimizationLevel: 2,
      },
    },
  ],
};

Available Options

Option Name Description Available Values Default Value
optimizationLevel Level of build speed optimization (See Optimization Levels) 0 ~ 3 1
esbuildMinifyOptions Options for esbuild via ESBuildMinifyPlugin object (Docs) { target: "es2015" }
removeProgressPlugin Whether to remove ProgressPlugin boolean process.env.NODE_ENV === "production"
disableSourceMap Whether to disable source map generation boolean process.env.NODE_ENV === "production"

Optimization Levels

0

No optimization. The preset just returns given webpack configuration.

1

Safe optimizations. You'll get enough build performance boost with this level.

  • Use ESBuild for minification instead of Terser
  • Disables source map generation when NODE_ENV=production
  • Disables webpack's ProgressPlugin when NODE_ENV=production

2

Aggressive optimizations. This would improve build speed slightly (probably about 1s, depends on machine) but might bring errors if you're using community addons.

  • Replace babel-loader with ESBuild in Manager (Storybook UI, Addons)

3

Dangerous optimizations. If your project is relying on Babel, this probably will break the build. But will dramatically increases build performance especially when the project has a lot of files (stories).

  • Replace babel-loader with ESBuild in Preview (Canvas, Docs Addon)

Limitations

ES5 Transpilation

Currently ESBuild does not fully support transpilation to ES5 (yet). If you set optimization level to higher than 1, your bundle might not work on browsers support only up to ES5.

Bundle size

Since the preset replaces Terser with ESBuild, you may observe some file size differences. But it should be very small and does not bring noticable loading performance impact.

storybook-addon-turbo-build's People

Contributors

pocka avatar

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.