From 204b8168da353bb97eac6611ecb0719512baf53e Mon Sep 17 00:00:00 2001
From: ADNY <66500121+ErKeLost@users.noreply.github.com>
Date: Mon, 15 Jan 2024 15:51:35 +0800
Subject: [PATCH] chore: update farm api docs (#50)
* chore: update farm api docs
* chore: update ai generate
* chore: update ai generate
* chore: update ai generate
* chore: update AI
* chore: update plugin siderBar
* chore: update theme
* chore: update md
* chore: update md
* chore: update md
* chore: update md
---
.vscode/settings.json | 1 +
docs/api/hmr-api.md | 1 +
docs/api/javascript-api.md | 1 +
docs/api/js-plugin-api.md | 1 +
docs/api/rust-api.md | 1 +
docs/api/rust-plugin-api.md | 1 +
docs/benchmark.md | 67 +++++--
docs/cli/build.md | 0
docs/cli/cli-api.md | 172 ++++++++++++++++++
docs/cli/preview.md | 0
docs/cli/start.md | 0
docs/cli/watch.md | 0
docs/config/compilation-options.md | 13 +-
docs/config/dev-server.md | 8 +-
docs/features/html.md | 72 ++++----
docs/plugins/writing-plugins/js-plugin.md | 43 +++--
docs/quick-start.mdx | 9 +-
docusaurus.config.js | 4 +-
i18n/zh/code.json | 21 ++-
.../current/api/hmr-api.md | 1 +
.../current/api/javascript-api.md | 1 +
.../current/api/js-plugin-api.md | 1 +
.../current/api/rust-api.md | 1 +
.../current/api/rust-plugin-api.md | 1 +
.../current/cli/cli-api.md | 172 ++++++++++++++++++
.../current/config/compilation-options.md | 16 +-
.../current/config/plugins-options.md | 13 +-
.../current/features/html.md | 69 +++----
.../plugins/writing-plugins/js-plugin.md | 2 +-
.../current/quick-start.mdx | 6 +-
package.json | 1 +
pnpm-lock.yaml | 13 ++
sidebars.js | 14 +-
src/css/_admonition.scss | 18 +-
34 files changed, 579 insertions(+), 165 deletions(-)
create mode 100644 docs/api/hmr-api.md
create mode 100644 docs/api/javascript-api.md
create mode 100644 docs/api/js-plugin-api.md
create mode 100644 docs/api/rust-api.md
create mode 100644 docs/api/rust-plugin-api.md
delete mode 100644 docs/cli/build.md
create mode 100644 docs/cli/cli-api.md
delete mode 100644 docs/cli/preview.md
delete mode 100644 docs/cli/start.md
delete mode 100644 docs/cli/watch.md
create mode 100644 i18n/zh/docusaurus-plugin-content-docs/current/api/hmr-api.md
create mode 100644 i18n/zh/docusaurus-plugin-content-docs/current/api/javascript-api.md
create mode 100644 i18n/zh/docusaurus-plugin-content-docs/current/api/js-plugin-api.md
create mode 100644 i18n/zh/docusaurus-plugin-content-docs/current/api/rust-api.md
create mode 100644 i18n/zh/docusaurus-plugin-content-docs/current/api/rust-plugin-api.md
create mode 100644 i18n/zh/docusaurus-plugin-content-docs/current/cli/cli-api.md
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 9d9b13307..26de816c5 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -16,6 +16,7 @@
"PUFY",
"raxjs",
"Rspack",
+ "shikiji",
"shulandmimi",
"tailwindcss",
"Turbopack"
diff --git a/docs/api/hmr-api.md b/docs/api/hmr-api.md
new file mode 100644
index 000000000..f92888fe3
--- /dev/null
+++ b/docs/api/hmr-api.md
@@ -0,0 +1 @@
+# Hmr Api
diff --git a/docs/api/javascript-api.md b/docs/api/javascript-api.md
new file mode 100644
index 000000000..d1daa55bc
--- /dev/null
+++ b/docs/api/javascript-api.md
@@ -0,0 +1 @@
+# JavaScript Api
diff --git a/docs/api/js-plugin-api.md b/docs/api/js-plugin-api.md
new file mode 100644
index 000000000..8e03502ca
--- /dev/null
+++ b/docs/api/js-plugin-api.md
@@ -0,0 +1 @@
+# Js Plugin Api
diff --git a/docs/api/rust-api.md b/docs/api/rust-api.md
new file mode 100644
index 000000000..91a278a54
--- /dev/null
+++ b/docs/api/rust-api.md
@@ -0,0 +1 @@
+# Rust Api
diff --git a/docs/api/rust-plugin-api.md b/docs/api/rust-plugin-api.md
new file mode 100644
index 000000000..da099bbc0
--- /dev/null
+++ b/docs/api/rust-plugin-api.md
@@ -0,0 +1 @@
+# Rust Plugin Api
diff --git a/docs/benchmark.md b/docs/benchmark.md
index e762ae4a8..566b7d545 100644
--- a/docs/benchmark.md
+++ b/docs/benchmark.md
@@ -1,33 +1,70 @@
# Benchmarks
+## Introduction
+
Using Turbopack's bench cases (1000 React components), see https://turbo.build/pack/docs/benchmarks.
+### Run this benchmark yourself
+
> Test Repo:https://github.com/farm-fe/performance-compare
>
> Test Machine(Linux Mint 21.1 Cinnamon, 11th Gen Intel© Core™ i5-11400 @ 2.60GHz × 6, 15.5 GiB)
+```ts
+# Install dependencies
+pnpm install
+
+# run benchmark
+pnpm benchmark
+```
+
+### Data
+
+| | **Startup** | **HMR (Root)** | **HMR (Leaf)** | **Production Build** |
+| ------- | ----------- | -------------- | -------------- | -------------------- |
+| Webpack | 8035ms | 345ms | 265ms | 11321ms |
+| Vite | 3078ms | 35ms | 18ms | 2266ms |
+| Rspack | 831ms | 104ms | 96ms | 724ms |
+| Farm | 403ms | 11ms | 10ms | 288ms |
+
---
-| | **Startup** | **HMR (Root)** | **HMR (Leaf)** | **Production Build** |
-| --------- | ----------- | -------------- | -------------- | -------------------- |
-| Webpack | 8035ms | 345ms | 265ms | 11321ms |
-| Vite | 3078ms | 35ms | 18ms | 2266ms |
-| Turbopack | 3731ms | 62ms | 54ms | 6442ms |
-| Rspack | 831ms | 104ms | 96ms | 724ms |
-| Farm | 403ms | 11ms | 10ms | 288ms |
+## metrics
+
+- Cold StartUp Time: The time it takes to develop a build without caching
+
+- Hot StartUp Time: The time it takes to develop a build with caching
+
+- Cold Production Build Time: The time it takes to build a production build without caching
+
+- Hot Production Build Time: The time it takes to build a production build with caching
+
+- HMR Time: The time it takes to apply an update to a file and send it to the development server to the response
+
+ - HMR Root: The time for updating a react component file that has no dependency
+
+ - HMR Leaf: The time for updating a root react component, normally it is named `App.tsx` or `index.tsx`
+
+### Benchmark for all metrics
+
+
+
+
+
+### Benchmark of HMR
-### Full Benchmark
+
-![performance](/img/20231204223204.png)
+
-### HMR Benchmark
+### Benchmark of Startup
-![performance](/img/hmr-linux.png)
+
-### Startup Benchmark
+
-![performance](/img/startup-linux.png)
+### Benchmark of Production Build
-### Production Build Benchmark
+
-![performance](/img/build-linux.png)
+
diff --git a/docs/cli/build.md b/docs/cli/build.md
deleted file mode 100644
index e69de29bb..000000000
diff --git a/docs/cli/cli-api.md b/docs/cli/cli-api.md
new file mode 100644
index 000000000..5552492c6
--- /dev/null
+++ b/docs/cli/cli-api.md
@@ -0,0 +1,172 @@
+# Farm CLI API
+
+The Farm CLI allows you to start, build, preview, and watch your application.
+
+To get a list of cli available to Farm, run the following command inside your command
+
+```json title="Terminal"
+npx farm -h
+```
+
+The output look like this:
+
+```json title="Terminal"
+farm/0.5.11
+
+Usage:
+ $ farm [root]
+
+Commands:
+ [root] Compile the project in dev mode and serve it with farm dev server
+ build compile the project in production mode
+ watch watch file change
+ preview compile the project in watch mode
+ clean [path] Clean up the cache built incrementally
+ plugin [command] Commands for manage plugins
+
+For more info, run any command with the `--help` flag:
+ $ farm --help
+ $ farm build --help
+ $ farm watch --help
+ $ farm preview --help
+ $ farm clean --help
+ $ farm plugin --help
+
+Options:
+ -l, --lazy lazyCompilation
+ --host specify host
+ --port specify port
+ --open open browser on server start
+ --hmr enable hot module replacement
+ --cors enable cors
+ --strictPort specified port is already in use, exit with error
+ -c, --config use specified config file
+ -m, --mode set env mode
+ --base public base path
+ --clearScreen allow/disable clear screen when logging
+ -h, --help Display this message
+ -v, --version Display version number
+```
+
+## Start
+
+`farm start` 命令用于启动开发服务器, 将代码进行开发环境的编译
+
+```json title="Terminal"
+Usage:
+ $ farm [root]
+
+Options:
+ -l, --lazy lazyCompilation
+ --host specify host
+ --port specify port
+ --open open browser on server start
+ --hmr enable hot module replacement
+ --cors enable cors
+ --strictPort specified port is already in use, exit with error
+ -c, --config use specified config file
+ -m, --mode set env mode
+ --base public base path
+ --clearScreen allow/disable clear screen when logging
+```
+
+
+
+## Build
+
+`farm build` 命令会在默认的 `dist` 目录下构建出可用于生产环境的产物。
+
+```json title="Terminal"
+Usage:
+ $ farm build
+
+Options:
+ -o, --outDir output directory
+ -i, --input input file path
+ -w, --watch watch file change
+ --targetEnv transpile targetEnv node, browser
+ --format transpile format esm, commonjs
+ --sourcemap output source maps for build
+ --treeShaking Eliminate useless code without side effects
+ --minify code compression at build time
+ -c, --config use specified config file
+ -m, --mode set env mode
+ --base public base path
+ --clearScreen allow/disable clear screen when logging
+ -h, --help Display this message
+```
+
+## Preview
+
+`farm preview` 用于在本地可以直接预览您的生产环境构建出的产物, 您需要提前执行 `farm build` 来构建出生产环境的产物
+
+```json title="Terminal"
+Usage:
+ $ farm preview
+
+Options:
+ --open [url] 启动时是否在浏览器中打开页面
+ --port 设置 Server 监听的端口号
+ --host 指定 Server 启动时监听的 host
+ -c --config 指定配置文件路径
+ -h, --help 显示命令帮助
+```
+
+## Watch
+
+`farm watch` 一般作用于 `node` 环境下监听文件变化并且重新构建
+
+```json title="Terminal"
+
+Usage:
+ $ farm watch
+
+Options:
+ --format transpile format esm, commonjs
+ -o, --outDir output directory
+ -i, --input input file path
+ -c, --config use specified config file
+ -m, --mode set env mode
+ --base public base path
+ --clearScreen allow/disable clear screen when logging
+ -h, --help Display this message
+```
+
+## Clean
+
+`farm clean` 由于 `farm` 提供的增量构建会在本地生成缓存文件, 如果在特定情况下(不可预知的编译错误)可能您需要清理缓存文件
+
+```json title="Terminal"
+Usage:
+ $ farm clean [path]
+
+Options:
+ --recursive Recursively search for node_modules directories and clean them
+ -c, --config use specified config file
+ -m, --mode set env mode
+ --base public base path
+ --clearScreen allow/disable clear screen when logging
+ -h, --help Display this message
+```
diff --git a/docs/cli/preview.md b/docs/cli/preview.md
deleted file mode 100644
index e69de29bb..000000000
diff --git a/docs/cli/start.md b/docs/cli/start.md
deleted file mode 100644
index e69de29bb..000000000
diff --git a/docs/cli/watch.md b/docs/cli/watch.md
deleted file mode 100644
index e69de29bb..000000000
diff --git a/docs/config/compilation-options.md b/docs/config/compilation-options.md
index 95c44353c..e75df201f 100644
--- a/docs/config/compilation-options.md
+++ b/docs/config/compilation-options.md
@@ -3,12 +3,7 @@
By default, Farm reads the configuration from the `farm.config.ts|js|mjs` file in the project root directory, an example configuration file:
```ts title="farm.config.ts"
-import type { UserConfig } from "@farmfe/core";
-
-function defineConfig(config: Config) {
- return config;
-}
-
+import { defineConfig } from "@farmfe/core";
export default defineConfig({
root: process.cwd(), // compiled root directory
// compile options
@@ -36,9 +31,9 @@ All compilation-related configuration is under the `compilation` field.
The entry point for the project. Input files can be `html`, `ts/js/tsx/jsx`, `css` or other files supported by plugins.
```tsx
-import type { UserConfig } from "@farmfe/core";
+import { defineConfig } from "@farmfe/core";
-export default {
+export default defineConfig({
compilation: {
input: {
index: "./index.html",
@@ -457,7 +452,7 @@ type BrowserTargetsRecord = Partial<
Configure which target browsers or browser versions to enable, for example:
```ts
-import type { UserConfig } from "@farmfe/core";
+import { defineConfig } from "@farmfe/core";
function defineConfig(config: UserConfig) {
return config;
diff --git a/docs/config/dev-server.md b/docs/config/dev-server.md
index ff03a9632..ec9365306 100644
--- a/docs/config/dev-server.md
+++ b/docs/config/dev-server.md
@@ -5,11 +5,7 @@
Configure the behavior of Farm Dev Server. Example:
```ts
-import type { UserConfig } from "@farmfe/core";
-
-function defineConfig(config: UserConfig) {
- return config;
-}
+import { defineConfig } from "@farmfe/core";
export default defineConfig({
// All dev server options are under server
@@ -98,7 +94,7 @@ Host on which the Web Socket server listens
Configure server proxy. Based on [koa-proxies](https://www.npmjs.com/package/koa-proxies) implementation, specific options refer to its documentation, example:
```ts
-import type { UserConfig } from "@farmfe/core";
+import { defineConfig } from "@farmfe/core";
function defineConfig(config: UserConfig) {
return config;
diff --git a/docs/features/html.md b/docs/features/html.md
index 475a0846a..3dbf7b86f 100644
--- a/docs/features/html.md
+++ b/docs/features/html.md
@@ -3,18 +3,21 @@ sidebar_position: 1
---
# Html
+
## Basic Usage
+
Farm support compile Html out of box, **and you should use Html as entry when build a web project**, for example:
```ts title="farm.config.ts"
-import type { UserConfig } from '@farmfe/core';
+import type { defineConfig } from "@farmfe/core";
-export default {
+export default defineConfig({
input: {
- index: './index.html' // using ./index.html as entry
- }
-}
+ index: "./index.html", // using ./index.html as entry
+ },
+});
```
+
:::note
If the input is not specified, default to `{ index: 'index.html' }`.
:::
@@ -27,26 +30,25 @@ and in `./index.html`, a `
+