npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

storybook-addon-turbo-build

v2.0.1

Published

Storybook Addon to improve build performance

Downloads

203,756

Readme

storybook-addon-turbo-build

npm license code style: prettier

A Storybook addon that improves your Storybook build time by tweaking webpack configuration. Compatible with Storybook v6.

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 note

For Storybook v7 (and later versions) users

This addon does not work with Storybook v7 and later versions. Those newer Storybook versions vastly improved build-time performance by adopting more efficient tools such as Vite or webpack 5. If you want to optimise your build performance further more, please tweak your configuration manually.

For Storybook v6 users

Storybook already does various build performance improvements. This addon mainly improves cold build, which is when you build Storybook without caches under your node_modules/.cache. There could be barely noticable differences in cache enabled builds. You should evaluate the build time before integrating this addon into your workflow.

Installation

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

# in other package managers
$ yarn add -D storybook-addon-turbo-build
$ pnpm i -D storybook-addon-turbo-build

Getting Started

Add this line in 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" | | managerTranspiler | Manager Webpack loader configuration that will replace babel-loader with | Object (loader config) or Function (LoaderReplacer) | Function returns a loader config object for esbuild-loader when Optimization Level >= 2, undefined otherwise | | previewTranspiler | Preview Webpack loader configuration that will replace babel-loader with | Object (loader config) or Function (LoaderReplacer) | Function returns a loader config object for esbuild-loader when Optimization Level >= 3, undefined otherwise |

LoaderReplacer

LoaderReplacer is a function that takes loader config object and rule then returns a new loader config object. Return null to remove the matching loader instead of to replace.

// Type Definition
type LoaderReplacer = (
  loader: webpack.RuleSetUseItem,
  rule: webpack.RuleSetRule
) => webpack.RuleSetUseItem | null;
// Replace babel-loader with swc-loader in Preview Webpack
{
  previewTranspiler(loader, rule) {
    return {
      loader: "swc-loader",
      options: {/* ... */}
    }
  }
}

// Simply remove babel-loader from Manager Webpack
{
  managerTranspiler() {
    return null
  }
}

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) and may causes an error 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 your 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.