Skip to content

Commit

Permalink
feat(generator): remove legacy storybook (#4951)
Browse files Browse the repository at this point in the history
  • Loading branch information
10Derozan committed Nov 16, 2023
1 parent dc80bbc commit 11b99a2
Show file tree
Hide file tree
Showing 31 changed files with 357 additions and 342 deletions.
6 changes: 6 additions & 0 deletions .changeset/dirty-apes-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/storybook-next-generator': minor
---

feat: installing builder-webpack when performing a new storybookv7 operation in a module project
feat: 在模块项目里执行新增 storybookv7 操作时安装 builder-webpack
7 changes: 7 additions & 0 deletions .changeset/lucky-balloons-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/generator-common': minor
'@modern-js/new-action': minor
---

feat: remove legacy storybook from module generator
feat: 从模块生成器里移除过时的 storybook
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ This command will create a template for Storybook, including:
If you are using an older version of the Storybook plugin, you can still run the command above to create templates and modify the package.json. You can also upgrade manually.
If you have made some custom configurations to Storybook in the older version, you need to move the configuration files from `root/config/storybook/` to the `root/.storybook/` directory.
If you have made some custom configurations to Storybook in the older version, you need to move the configuration file `root/config/storybook/main.(j|t)s` to `root/.storybook/main.(j|t)s`.
Specify framework as `@modern-js/storybook` in `root/.storybook/main.(j|t)s`.
And then add the following lines in `root/.storybook/main.(j|t)s`, specify framework as `@modern-js/storybook`.
```diff
const config = {
Expand Down Expand Up @@ -180,18 +180,17 @@ const config = {
export default config;
```
## Command Line Interface
@modern-js/storybook proxies some of the storybook cli commands.
### storybook dev
Start Storybook, more details at https://storybook.js.org/docs/react/api/cli-options#dev.
Start Storybook, more details at <https://storybook.js.org/docs/react/api/cli-options#dev>.
### storybook build
Build Storybook for production, more details at https://storybook.js.org/docs/react/api/cli-options#build.
Build Storybook for production, more details at <https://storybook.js.org/docs/react/api/cli-options#build>.
## ConfigFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ $ npx modern new

若正使用旧版本 Storybook 插件,那么你仍然可以运行上方的命令,来创建模版以及修改 package.json,也可以手动升级。

若你在旧版本对 storybook 进行了一些自定义配置,需要将配置文件从 `root/config/storybook/` 移动到 `root/.storybook/` 目录
若你在旧版本对 storybook 进行了一些自定义配置,需要将配置文件 `root/config/storybook/main.(j|t)s` 移动到 `root/.storybook/main.(j|t)s`

`root/.storybook/main.(j|t)s` 中指定 framework 为 @modern-js/storybook
并在 `root/.storybook/main.(j|t)s` 中添加以下配置,指定 framework 为 @modern-js/storybook

```diff
const config = {
Expand Down Expand Up @@ -116,6 +116,7 @@ export default config;
用于指定配置文件路径。

例如

```javascript filename='.storybook/main.js'
const config = {
framework: {
Expand All @@ -137,6 +138,7 @@ export default config;
指定底层构建工具使用 Webpack 还是 Rspack。请确保安装了对应的 provider,使用 Webpack 请安装 @modern-js/builder-webpack-provider,使用 Rspack 请安装 @modern-js/builder-rspack-provider

例如

```javascript filename='.storybook/main.js'
const config = {
framework: {
Expand All @@ -158,6 +160,7 @@ export default config;
更改 builder 的配置,该配置比配置文件拥有更高的优先级,若不想使用配置文件,也可直接在此处指定 Modern.js builder 配置。

例如

```javascript filename='.storybook/main.js'
const config = {
framework: {
Expand All @@ -182,11 +185,11 @@ export default config;

### storybook dev

启动 Storybook,详情请看 https://storybook.js.org/docs/react/api/cli-options#dev
启动 Storybook,详情请看 <https://storybook.js.org/docs/react/api/cli-options#dev>

### storybook build

对 Storybook 进行生产环境构建,详情请看 https://storybook.js.org/docs/react/api/cli-options#build
对 Storybook 进行生产环境构建,详情请看 <https://storybook.js.org/docs/react/api/cli-options#build>

## 配置文件

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,6 @@ const tailwind = {
content: [
'./src/**/*.{js,jsx,ts,tsx}',
'./config/html/**/*.{html,ejs,hbs}',
'./storybook/**/*',
],
};
```
Expand Down
19 changes: 1 addition & 18 deletions packages/document/module-doc/docs/en/api/config/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,12 @@ sidebar_position: 3

This section describes all configuration of Modern.js Module related to debugging tools.

```ts
export default {
dev: {
storybook: {
/* Storybook Config */
},
},
};
```

## storybook

:::warning
Deprecated: This configuration is deprecated and only applicable to Storybook V6. For configuring the new Storybook, please refer to [Using Storybook](https://modernjs.dev/builder/guide/advanced/storybook.html).
**Deprecated**: This configuration is deprecated and only applicable to Storybook V6. Please see [使用Storybook](/guide/basic/using-storybook) to get more info.
:::

**Requirements**:

- Turn on Storybook debugging or install the `@modern-js/plugin-storybook` plugin.
- Register the `@modern-js/plugin-storybook` plugin。

> For more information on how to enable Storybook debugging, please refer to:["Storybook"](guide/basic/use-micro-generator#storybook)
### storybook.webpack

- **Type**: `object | Function | undefined`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export interface BuildResult {

module-tools also provides the `build --platform` command to perform specific build tasks.

For example, after installing the Storybook plugin, you can run `build --platform` or `build --platform storybook` to perform Storybook build tasks. This is because the Storybook plugin is based on the buildPlatform Hooks.
For example, after installing the Module Doc plugin, you can run `build --platform` or `build --platform doc` to perform Doc build tasks.

Hooks are triggered in the following order after executing `build --platform`.

Expand All @@ -160,9 +160,9 @@ export const myPlugin = (): CliPlugin<ModuleTools> => ({
registerBuildPlatform(): RegisterBuildPlatformResult {
// ...
return {
platform: 'stroybook',
platform: 'doc',
build() {
// run storybook logic
// logic
},
}, };
},
Expand Down Expand Up @@ -335,12 +335,6 @@ export interface DevToolData {
}
```

<!-- :::tip About disableRunBuild configuration
When dev a project, it may be possible to set `disableRunBuild: true` to disable build tasks for source execution (in listening mode) if you only need to dev code functionality.
The currently supported Storybook dev supports using source code artifacts as dev objects, so `disableRunBuild: false` in the Storybook plugin.
::: -->

### `beforeDev`

Triggered before the dev task is executed after all dev tool metadata has been collected.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ The `dev` command provided by the Modern.js Module is mainly used for debugging

## The overall flow of the command run

1. When the `dev` command is executed, Modern.js Module starts looking for debugging tools or tasks that can be executed. A debugging tool or task is a Modern.js Module debugging tool plugin like Storybook.
1. When the `dev` command is executed, Modern.js Module starts looking for debugging tools or tasks that can be executed. A debugging tool or task is a Modern.js Module debugging tool plugin like module doc.
2. When a debugging tool is found, it is executed immediately.
3. When multiple debugging tools are found, the debugging tools list menu is displayed. A debug tool can be started by selecting the name option corresponding to it.
4. When no debug tool is found, the user is informed that no debug tool is available.

In addition to the `dev` command, you can also start a debugging tool or task directly by using the `dev [debug tool name]` option.


## Extending the dev command

If you need to extend the dev command, or rather provide your own Modern.js Module debugging tool plugin, then you will need to know the following first.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ When you want to start a project build, you can execute the `modern build` comma
- The `-no-dts` option can be used when the DTS type file generation and type checking behavior of the project needs to be turned off. **Note: The generation of type files depends on the results of type checking. If type checking is turned off, then type files will not be generated either**.
- The `--no-clear` option can be used when the automatic clearing of the output directory needs to be turned off.

In addition to the above, Modern.js Module also support `platform` build mode, which can be used to perform build tasks for other tools. For example if you are using legacy storybook plugin, it is currently officially supported to start a Storybook build task to generate Storybook artifacts by executing the `modern build --platform` or `modern build --platform storybook` commands after installing the `@modern-js/plugin-storybook` plugin.
In addition to the above, Modern.js Module also support `platform` build mode, which can be used to perform build tasks for other tools. For example if you are using module doc plugin, it is currently officially supported to start a doc build task to generate html artifacts by executing the `modern build --platform` or `modern build --platform doc` commands after installing the `@modern-js/plugin-module-doc` plugin.

:::tip
When executing a Storybook build, if you need to read the build artifacts of the project. Then **don't forget to execute the `modern build` command to ensure the existence of the project's build artifacts before executing the `modern build --platform` command to start the Storybook build**.
If you are using new storybook ability, it should be built by `storybook build`.
When executing a doc build, if you need to read the build artifacts of the project. Then **don't forget to execute the `modern build` command to ensure the existence of the project's build artifacts before executing the `modern build --platform` command to start the doc build**.
:::

## `modern new`
Expand All @@ -58,7 +57,7 @@ The `modern new` command is used to start the microgenerator functionality, whic
The following features can currently be enabled.

- Testing support
- Storybook debugging
- Storybook V7
- Tailwind CSS support
- Modern.js Runtime API

Expand All @@ -80,7 +79,7 @@ Commands:

The Modern.js Module provides the ability to use debugging tools, which can be started with the `modern dev` command. Note, however, that no debugging-related plugins are provided by default, so executing `modern dev` will prompt: _"No dev tools found available "_.

The officially supported debugging tool is [Storybook](https://storybook.js.org/), so you can run `modern dev` or `modern dev storybook` to execute it after you run `modern new` to enable it.
The officially supported debugging tool is [Rspress](https://rspress.dev/), so you can run `modern dev` or `modern dev doc` to execute it after you run `modern new` to enable it.

## `modern test`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ export default defineConfig({

## Storybook

The **Storybook feature** can be enabled when we want to debug a component or a common module. When this feature is enabled, **the `stories` directory and related files are created in the project directory, and a new `"@modern-js/storybook"` dependency is added to package.json**.

For more information on how to start Storybook and how to use it, check out the following link.

- [`using Storybook`](https://modernjs.dev/builder/guide/advanced/storybook.html)
The **Storybook feature** can be enabled when we want to debug a component or a common module. When this feature is enabled, **the `stories` directory and `.storybook` directory are created in the project directory, and a new `"@modern-js/storybook"` dependency is added to package.json**.

## Tailwind CSS Support

Expand Down
Loading

0 comments on commit 11b99a2

Please sign in to comment.