-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(builder): add builder CLI usage guide (#4081)
* docs(builder): add builder CLI usage guide * docs: fix link * docs: update
- Loading branch information
1 parent
dda37bf
commit 6526966
Showing
6 changed files
with
290 additions
and
7 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
packages/document/builder-doc/docs/en/guide/basic/builder-cli.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# Use Builder CLI | ||
|
||
Modern.js Builder provides a lightweight CLI tool that includes basic commands such as `dev` and `build`. It is primarily used for building non-React projects. | ||
|
||
- For React projects, we recommend using the Modern.js framework directly. Please refer to [Modern.js - Quick Start](https://modernjs.dev/en/guides/get-started/quick-start.html) for more information. | ||
- For non-React projects, such as developing a Vue project, you can use the Builder CLI tool to build your project. | ||
|
||
## Install | ||
|
||
You need to install two packages: | ||
|
||
- `@modern-js/builder-cli` is the CLI tool for Builder, providing basic CLI commands and automatically loading the installed Provider in the current project. | ||
- `@modern-js/builder-webpack-provider` or `@modern-js/builder-rspack-provider`, they are Providers for Builder, offering build capabilities based on webpack or Rspack. | ||
|
||
```bash | ||
# Using webpack for bundling | ||
pnpm add @modern-js/builder-cli @modern-js/builder-webpack-provider -D | ||
|
||
# Using Rspack for bundling | ||
pnpm add @modern-js/builder-cli @modern-js/builder-rspack-provider -D | ||
``` | ||
|
||
## Commands | ||
|
||
Builder CLI provides the following commands to help you quickly start a development server, build production-ready code, and more. | ||
|
||
### builder dev | ||
|
||
The `builder dev` command is used to start a local development server and compile the source code in the development environment. | ||
|
||
```bash | ||
Usage: builder dev [options] | ||
|
||
Options: | ||
-h, --help display help for command | ||
``` | ||
|
||
### builder build | ||
|
||
The `builder build` command will build the outputs for production in the `dist/` directory by default. | ||
|
||
```bash | ||
Usage: builder build [options] | ||
|
||
Options: | ||
-h, --help display help for command | ||
``` | ||
|
||
### builder serve | ||
|
||
The `builder serve` command is used to preview the production build outputs locally. Note that you need to execute the `builder build` command beforehand to generate the corresponding outputs. | ||
|
||
```bash | ||
Usage: builder serve [options] | ||
|
||
Options: | ||
-h, --help display help for command | ||
``` | ||
|
||
## Configuration | ||
|
||
Builder CLI will read the `builder.config.ts` configuration file located in the root directory of your project by default. You can use [all the configuration options](/api/index) provided by Builder in the configuration file. | ||
|
||
```ts title="builder.config.ts" | ||
import { defineConfig } from '@modern-js/builder-cli'; | ||
|
||
export default defineConfig({ | ||
output: { | ||
disableTsChecker: true, | ||
}, | ||
}); | ||
``` | ||
|
||
When you use Rspack as the bundler, there are some differences in configuration types between webpack and Rspack. Therefore, you need to specify the `'rspack'` generic for `defineConfig`: | ||
|
||
```diff title="builder.config.ts" | ||
- export default defineConfig({ | ||
+ export default defineConfig<'rspack'>({ | ||
// ... | ||
}); | ||
``` | ||
|
||
## Build Entry | ||
|
||
By default, Builder CLI uses `src/index.(js|ts|jsx|tsx)` as the build entry. You can modify the build entry using the `source.entries` configuration option. | ||
|
||
- **Type:** | ||
|
||
```ts | ||
type Entries = Record<string, string>; | ||
``` | ||
|
||
- **Default:** | ||
|
||
```ts | ||
const defaultEntry = { | ||
index: 'src/index.(js|ts|jsx|tsx)', | ||
}; | ||
``` | ||
|
||
- **Example:** | ||
|
||
```ts title="builder.config.ts" | ||
import { defineConfig } from '@modern-js/builder-cli'; | ||
|
||
export default defineConfig({ | ||
source: { | ||
entries: { | ||
foo: './src/pages/foo/index.ts', | ||
bar: './src/pages/bar/index.ts', | ||
}, | ||
}, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
packages/document/builder-doc/docs/zh/guide/basic/builder-cli.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# 使用 Builder CLI | ||
|
||
Modern.js Builder 提供了一个轻量的 CLI 工具,包含 dev、build 等基础命令,它主要用于构建非 React 项目。 | ||
|
||
- 对于 React 项目,我们建议直接使用 Modern.js 框架,参考 [Modern.js - 快速上手](https://modernjs.dev/guides/get-started/quick-start.html)。 | ||
- 对于非 React 项目,比如开发一个 Vue 项目,那么你可以使用 Builder CLI 工具来构建你的项目。 | ||
|
||
## 安装 | ||
|
||
你需要安装两个包,其中: | ||
|
||
- `@modern-js/builder-cli` 为 Builder 的 CLI 工具,提供基础的 CLI 命令,并会自动加载当前项目中安装的 Provider。 | ||
- `@modern-js/builder-webpack-provider` 或 `@modern-js/builder-rspack-provider`,它们是 Builder 的 Provider,提供基于 webpack 或 Rspack 的构建能力。 | ||
|
||
```bash | ||
# 使用 webpack 打包 | ||
pnpm add @modern-js/builder-cli @modern-js/builder-webpack-provider -D | ||
|
||
# 使用 Rspack 打包 | ||
pnpm add @modern-js/builder-cli @modern-js/builder-rspack-provider -D | ||
``` | ||
|
||
## 命令 | ||
|
||
Builder CLI 提供了以下命令,可以帮助你快速启动开发服务器、构建生产环境代码等。 | ||
|
||
### builder dev | ||
|
||
`builder dev` 命令用于启动一个本地开发服务器,对源代码进行开发环境编译。 | ||
|
||
```bash | ||
Usage: edenx dev [options] | ||
|
||
Options: | ||
-h, --help display help for command | ||
``` | ||
|
||
### builder build | ||
|
||
`builder build` 命令默认会在 `dist/` 目录下构建出可用于生产环境的产物。 | ||
|
||
```bash | ||
Usage: builder build [options] | ||
|
||
Options: | ||
-h, --help display help for command | ||
``` | ||
|
||
### builder serve | ||
|
||
`builder serve` 命令用于在本地预览生产环境构建的产物, 注意你需要提前执行 `builder build` 命令构建出对应产物。 | ||
|
||
```bash | ||
Usage: builder serve [options] | ||
|
||
Options: | ||
-h, --help display help for command | ||
``` | ||
|
||
## 配置 | ||
|
||
Builder CLI 默认会读取项目根目录下的 `builder.config.ts` 配置文件,你可以在配置文件中使用 Builder 提供的[所有配置项](/api/index)。 | ||
|
||
```ts title="builder.config.ts" | ||
import { defineConfig } from '@modern-js/builder-cli'; | ||
|
||
export default defineConfig({ | ||
output: { | ||
disableTsChecker: true, | ||
}, | ||
}); | ||
``` | ||
|
||
当你使用 Rspack 作为打包工具时,由于 webpack 和 Rspack 的配置类型存在一些差异,需要为 defineConfig 指定 `<'rspack'>` 泛型: | ||
|
||
```diff title="builder.config.ts" | ||
- export default defineConfig({ | ||
+ export default defineConfig<'rspack'>({ | ||
// ... | ||
}); | ||
``` | ||
|
||
## 构建入口 | ||
|
||
Builder CLI 默认会使用 `src/index.(js|ts|jsx|tsx)` 作为构建入口,你可以使用 `source.entries` 配置项来修改构建入口。 | ||
|
||
- **类型:** | ||
|
||
```ts | ||
type Entries = Record<string, string>; | ||
``` | ||
|
||
- **默认值:** | ||
|
||
```ts | ||
const defaultEntry = { | ||
index: 'src/index.(js|ts|jsx|tsx)', | ||
}; | ||
``` | ||
|
||
- **示例:** | ||
|
||
```ts title="builder.config.ts" | ||
import { defineConfig } from '@modern-js/builder-cli'; | ||
|
||
export default defineConfig({ | ||
source: { | ||
entries: { | ||
foo: './src/pages/foo/index.ts', | ||
bar: './src/pages/bar/index.ts', | ||
}, | ||
}, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/e2e/builder/cases/builder-cli/builder-cli-webpack/builder.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters