Docs
Storybook Docs

升级 Storybook

前端生态系统是一个快速发展的地方。定期的依赖升级是一种生活方式,无论是升级框架、库、工具还是以上所有!Storybook 提供了一些资源来帮助减轻升级的痛苦。

¥The frontend ecosystem is a fast-moving place. Regular dependency upgrades are a way of life, whether upgrading a framework, library, tooling, or all of the above! Storybook provides a few resources to help ease the pain of upgrading.

升级脚本

¥Upgrade script

最常见的升级是 Storybook 本身。Storybook 发布 遵循 语义版本控制。我们不断发布带有错误修复的补丁版本,每隔几个月发布具有新功能的 Storybook 小版本,大约每年发布一次具有重大更改的 Storybook 主要版本。

¥The most common upgrade is Storybook itself. Storybook releases follow Semantic Versioning. We publish patch releases with bug fixes continuously, minor versions of Storybook with new features every few months, and major versions of Storybook with breaking changes roughly once per year.

为了帮助减轻保持 Storybook 最新的痛苦,我们提供了一个命令行脚本:

¥To help ease the pain of keeping Storybook up-to-date, we provide a command-line script:

npx storybook@latest upgrade

upgrade 命令将使用你指定的任何版本。例如:

¥The upgrade command will use whichever version you specify. For example:

  • storybook@latest upgrade 将升级到最新版本

    ¥storybook@latest upgrade will upgrade to the latest version

  • storybook@7.6.10 upgrade 将升级到 7.6.10

    ¥storybook@7.6.10 upgrade will upgrade to 7.6.10

  • storybook@7 upgrade 将升级到最新的 7.x.x 版本

    ¥storybook@7 upgrade will upgrade to the newest 7.x.x version

运行命令后,脚本将:

¥After running the command, the script will:

  • 将项目中的所有 Storybook 包升级到指定版本

    ¥Upgrade all Storybook packages in your project to the specified version

  • 运行相关 automigrations,将当前版本和指定版本之间的 重大更改 考虑在内

    ¥Run the relevant automigrations factoring in the breaking changes between your current version and the specified version

除了运行命令之外,我们还建议检查 MIGRATION.md 文件,以获取可能影响升级的相关更改和弃用的详细日志。

¥In addition to running the command, we also recommend checking the MIGRATION.md file, for the detailed log of relevant changes and deprecations that might affect your upgrade.

验证升级

¥Verifying the upgrade

为了帮助你验证升级是否已完成以及你的项目是否仍在按预期运行,Storybook CLI 提供了 doctor 命令,允许你对项目进行健康检查,以查找升级后可能出现的常见问题,例如重复的依赖、不兼容的插件或不匹配的版本。要执行健康检查,请使用你选择的包管理器运行以下命令:

¥To help you verify that the upgrade was completed and that your project is still working as expected, the Storybook CLI provides the doctor command that allows you to do a health check on your project for common issues that might arise after an upgrade, such as duplicated dependencies, incompatible addons or mismatched versions. To perform the health check, run the following command with your package manager of choice:

npx storybook@latest doctor

自动迁移脚本

¥Automigrate script

Storybook 升级并不是唯一需要考虑的事情:生态系统的变化也带来了挑战。例如,知名的前端框架(如 AngularNext.jsSvelte)已对其生态系统进行了重大更改,因此即使你不升级 Storybook 版本,也可能需要相应地更新配置。这就是 Automigrate 的用途:

¥Storybook upgrades are not the only thing to consider: changes in the ecosystem also present challenges. For example well-known frontend frameworks, such as Angular, Next.js or Svelte have been rolling out significant changes to their ecosystem, so even if you don't upgrade your Storybook version, you might need to update your configuration accordingly. That's what Automigrate is for:

npx storybook@latest automigrate

它运行一组标准配置检查,解释哪些可能过时,并自动为你修复它。它还指向相关文档,以便你了解更多信息。它作为 storybook upgrade 命令的一部分自动运行,但如果你不想升级 Storybook,它也可以单独使用。

¥It runs a set of standard configuration checks, explains what is potentially out-of-date, and offers to fix it for you automatically. It also points to the relevant documentation so you can learn more. It runs automatically as part of storybook upgrade command, but it's also available on its own if you don't want to upgrade Storybook.

预发布

¥Prereleases

除上述内容外,Storybook 还在不断发展,我们几乎每天都会发布预发布版本。预发布是在新功能普遍可用之前试用它们的最佳方式,我们尽最大努力保持它们尽可能稳定,尽管这并不总是可行的。

¥In addition to the above, Storybook is under constant development, and we publish pre-release versions almost daily. Pre-releases are the best way to try out new features before they are generally available, and we do our best to keep them as stable as possible, although this is not always possible.

要升级到最新的预发布版本:

¥To upgrade to the latest pre-release:

npx storybook@next upgrade

upgrade 命令将使用你指定的任何版本。例如:

¥The upgrade command will use whichever version you specify. For example:

  • storybook@next upgrade 将升级到最新的预发布版本

    ¥storybook@next upgrade will upgrade to the newest pre-release version

  • storybook@8.0.0-beta.1 upgrade 将升级到 8.0.0-beta.1

    ¥storybook@8.0.0-beta.1 upgrade will upgrade to 8.0.0-beta.1

  • storybook@8 upgrade 将升级到最新的 8.x 版本

    ¥storybook@8 upgrade will upgrade to the newest 8.x version

如果你想降级到稳定版本,请手动编辑 package.json 中的软件包版本号并重新安装。

¥If you'd like to downgrade to a stable version, manually edit the package version numbers in your package.json and re-install.

Storybook 收集完全匿名的数据以帮助我们改善用户体验。参与是可选的,如果你不想分享任何信息,你可以选择 opt-out

¥Storybook collects completely anonymous data to help us improve user experience. Participation is optional, and you may opt-out if you'd not like to share any information.