Skip to content

Commit

Permalink
docs: add rsbuild-plugin guide (#5310)
Browse files Browse the repository at this point in the history
  • Loading branch information
9aoy authored Jan 25, 2024
1 parent fac9a6a commit b3a0696
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
sidebar_position: 21
title: Using Rsbuild Plugin
---

# Using Rsbuild Plugin

## Introduce Rsbuild Plugin

Rsbuild is the build tool of Modern.js. You can modify the default build behavior and add various additional features by adding the Rsbuild plugin, including but not limited to:

- Modifying Rspack configurations
- Processing new file types
- Modifying or compiling files
- Deploying artifacts

You can register the Rsbuild plugin through the `builderPlugins` option in `modern.config.ts`, see [builderPlugins](/configure/app/builder-plugins) for details.

## Official Plugins

:::tip
Most plugins in Rsbuild have been built into Modern.js. For example, when you need to inject the Polyfill of the Node module, you can directly use the [output.disableNodePolyfill](/configure/app/output/disable-node-polyfill.html) configuration.
:::

### Builtin Plugins

Here are the official Rsbuild plugins built into Modern.js:

| Plugin Name | Introduce | Modern.js Link |
| ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| [React Plugin](https://rsbuild.dev/plugins/list/plugin-react) | Provides support for React | - |
| [SVGR Plugin](https://rsbuild.dev/plugins/list/plugin-svgr) | Support convert SVG to React components | [output.disableSvgr](/configure/app/output/disable-svgr)<br />[output.svgDefaultExport](/configure/app/output/svg-default-export) |
| [Styled Components Plugin](https://rsbuild.dev/plugins/list/plugin-styled-components) | Provides compile-time support for styled-components | [tools.styledComponents](/configure/app/tools/styled-components.html) |
| [Assets Retry Plugin](https://rsbuild.dev/plugins/list/plugin-assets-retry) | Used to automatically resend requests when static assets fail to load | [output.assetsRetry](/configure/app/output/assets-retry.html) |
| [Type Check Plugin](https://rsbuild.dev/plugins/list/plugin-type-check) | Used to run TypeScript type checker on a separate process | [output.disableTsChecker](/configure/app/output/disable-ts-checker.html)<br />[tools.tsChecker](/configure/app/tools/ts-checker.html) |
| [Node Polyfill Plugin](https://rsbuild.dev/plugins/list/plugin-node-polyfill) | Used to inject polyfills of Node core modules in the browser side | [output.disableNodePolyfill](/configure/app/output/disable-node-polyfill.html) |
| [Source Build Plugin](https://rsbuild.dev/plugins/list/plugin-source-build) | Supports referencing source code from other subdirectories | [experiments.sourceBuild](/configure/app/experiments/source-build.html) |
| [Check Syntax Plugin](https://rsbuild.dev/plugins/list/plugin-check-syntax) | Used to analyze the syntax compatibility of artifacts | [security.checkSyntax](/configure/app/security/check-syntax.html) |
| [CSS Minimizer Plugin](https://rsbuild.dev/plugins/list/plugin-css-minimizer) | Used to customize CSS minimizer, switch to [cssnano](https://cssnano.co/) or other tools for CSS compression | [tools.minifyCss](/configure/app/tools/minify-css.html) |
| [Pug Plugin](https://rsbuild.dev/plugins/list/plugin-pug) | Provides support for the Pug template engine | [tools.pug](/configure/app/tools/pug.html) |
| [Rem Plugin](https://rsbuild.dev/plugins/list/plugin-rem) | Implements the rem adaptive layout for mobile pages | [output.convertToRem](/configure/app/output/convert-to-rem.html) |
| [YAML Plugin](https://rsbuild.dev/plugins/list/plugin-yaml) | Used to import YAML files and convert them into JavaScript objects | [TOML File](/guides/basic-features/json-files.html#toml-file) |
| [TOML Plugin](https://rsbuild.dev/plugins/list/plugin-toml) | Used to import TOML files and convert them into JavaScript objects | [YAML File](/guides/basic-features/json-files.html#yaml-file) |

### Un-builtin Plugins

Here are the official Rsbuild plugins that are not built into Modern.js:

- [Image Compress Plugin](https://rsbuild.dev/plugins/list/plugin-image-compress): Compress the image resources used in the project.
- [Stylus Plugin](https://rsbuild.dev/plugins/list/plugin-stylus): Use Stylus as the CSS preprocessor.
- [UMD Plugin](https://rsbuild.dev/plugins/list/plugin-umd): Used to build outputs in UMD format.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
sidebar_position: 21
title: 使用 Rsbuild 插件
---

# 使用 Rsbuild 插件

## 插件介绍

Rsbuild 是 Modern.js 底层的构建工具,可通过添加 Rsbuild 插件修改默认的构建行为并添加各类额外功能,包括但不限于:

- 修改 Rsbuild 配置
- 处理新的文件类型
- 修改或编译文件
- 部署产物

你可以在 `modern.config.ts` 中通过 `builderPlugins` 选项来注册 Rsbuild 插件,详见 [builderPlugins 构建插件](/configure/app/builder-plugins.html)

## 官方插件

:::tip
Rsbuild 中大部分插件已内置在 Modern.js 中,如:需要注入 Node 模块的 Polyfill 时,可直接使用 [output.disableNodePolyfill](/configure/app/output/disable-node-polyfill.html) 配置项。
:::

### 内置插件

以下是已在 Modern.js 中内置的 Rsbuild 官方插件:

| 插件 | 介绍 | Modern.js 链接 |
| -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| [React 插件](https://rsbuild.dev/zh/plugins/list/plugin-react) | 提供对 React 的支持 | - |
| [SVGR 插件](https://rsbuild.dev/zh/plugins/list/plugin-svgr) | 支持将 SVG 图片转换为一个 React 组件使用 | [output.disableSvgr](/configure/app/output/disable-svgr)<br />[output.svgDefaultExport](/configure/app/output/svg-default-export) |
| [Styled Components 插件](https://rsbuild.dev/zh/plugins/list/plugin-styled-components) | 提供对 styled-components 的编译时支持 | [tools.styledComponents](/configure/app/tools/styled-components.html) |
| [Assets Retry 插件](https://rsbuild.dev/zh/plugins/list/plugin-assets-retry) | 用于在静态资源加载失败时自动发起重试请求 | [output.assetsRetry](/configure/app/output/assets-retry.html) |
| [Type Check 插件](https://rsbuild.dev/zh/plugins/list/plugin-type-check) | 用于在单独的进程中运行 TypeScript 类型检查 | [output.disableTsChecker](/configure/app/output/disable-ts-checker.html)<br />[tools.tsChecker](/configure/app/tools/ts-checker.html) |
| [Node Polyfill 插件](https://rsbuild.dev/zh/plugins/list/plugin-node-polyfill) | 用于注入 Node 核心模块在浏览器端的 polyfills | [output.disableNodePolyfill](/configure/app/output/disable-node-polyfill.html) |
| [Source Build 插件](https://rsbuild.dev/zh/plugins/list/plugin-source-build) | 用于 monorepo 场景,支持引用其他子目录的源代码,并完成构建和热更新 | [experiments.sourceBuild](/configure/app/experiments/source-build.html) |
| [Check Syntax 插件](https://rsbuild.dev/zh/plugins/list/plugin-check-syntax) | 用于分析产物的语法兼容性,判断是否存在导致兼容性问题的高级语法 | [security.checkSyntax](/configure/app/security/check-syntax.html) |
| [CSS Minimizer 插件](https://rsbuild.dev/zh/plugins/list/plugin-css-minimizer) | 用于自定义 CSS 压缩工具,切换到 [cssnano](https://cssnano.co/) 或其他工具进行 CSS 压缩。 | [tools.minifyCss](/configure/app/tools/minify-css.html) |
| [Pug 插件](https://rsbuild.dev/zh/plugins/list/plugin-pug) | 提供对 Pug 模板引擎的支持 | [tools.pug](/configure/app/tools/pug.html) |
| [Rem 插件](https://rsbuild.dev/zh/plugins/list/plugin-rem) | 用于实现移动端页面的 rem 自适应布局 | [output.convertToRem](/configure/app/output/convert-to-rem.html) |
| [YAML 插件](https://rsbuild.dev/zh/plugins/list/plugin-yaml) | 用于引用 YAML 文件,并将其转换为 JavaScript 对象 | [TOML 文件](/guides/basic-features/json-files.html#toml-文件) |
| [TOML 插件](https://rsbuild.dev/zh/plugins/list/plugin-toml) | 用于引用 TOML 文件,并将其转换为 JavaScript 对象 | [YAML 文件](/guides/basic-features/json-files.html#yaml-文件) |

### 未内置插件

以下是未在 Modern.js 中内置的 Rsbuild 官方插件:

- [Image Compress 插件](https://rsbuild.dev/zh/plugins/list/plugin-image-compress):将项目中用到的图片资源进行压缩处理。
- [Stylus 插件](https://rsbuild.dev/zh/plugins/list/plugin-stylus):使用 Stylus 作为 CSS 预处理器。
- [UMD 插件](https://rsbuild.dev/zh/plugins/list/plugin-umd):用于构建 UMD 格式的产物。
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Overview

## Official Plugin
## Official Plugins

* [@modern-js/plugin-module-import](./plugin-import.md):Use SWC to provide the same ability as [`babel-plugin-import`](https://github.com/umijs/babel-plugin-import).
* [@modern-js/plugin-module-banner](./plugin-banner.md):Add custom content, such as copyright information, to the top and bottom of each JS and CSS file.
Expand Down

0 comments on commit b3a0696

Please sign in to comment.