Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new docs #101

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a9dec3c
chore: update new docs
ErKeLost Jun 12, 2024
efd4f18
chore: update homepage
ErKeLost Jun 12, 2024
25b4f0f
chore: update style
ErKeLost Jun 12, 2024
caa87be
chore: update code
ErKeLost Jun 12, 2024
fb1f432
chore: update homepage
ErKeLost Jun 12, 2024
ccd5ca6
chore: update code
ErKeLost Jun 12, 2024
68d9fcc
chore: update background
ErKeLost Jun 13, 2024
b30089a
chore: update code
ErKeLost Jun 13, 2024
4a45f78
chore: update home page
ErKeLost Jun 13, 2024
b1ad7a8
chore: update footer
ErKeLost Jun 13, 2024
da65a7b
chore: update code
ErKeLost Jun 13, 2024
a461bce
chore: update code
ErKeLost Jun 13, 2024
42e59b1
chore: update code
ErKeLost Jun 19, 2024
b5847f5
chore: update homepage
ErKeLost Jun 19, 2024
b352b24
chore: update homepage
ErKeLost Jun 19, 2024
a60ea03
chore: update code
ErKeLost Jun 20, 2024
71c524d
chore: update new tabs
ErKeLost Jun 21, 2024
2b5d665
chore: update docs
ErKeLost Jun 23, 2024
f10a8b3
chore: update docs
ErKeLost Jun 23, 2024
ba5d161
chore: update docs
ErKeLost Jun 24, 2024
402c271
chore: update code
ErKeLost Jun 24, 2024
8461bd9
chore: update code
ErKeLost Jun 24, 2024
cbc2819
chore: update docs
ErKeLost Jun 25, 2024
73da384
chore: fix build error
ErKeLost Jun 25, 2024
ceefba5
feat: add `FAQ` (#111)
RSS1102 Jun 25, 2024
7903483
chore: update color
ErKeLost Jun 26, 2024
b370a1e
chore: update color
ErKeLost Jun 26, 2024
54141f3
chore: update template
ErKeLost Jun 26, 2024
9d43a19
feat: add plugins
CCherry07 Jun 28, 2024
1915079
Merge branch 'feat-plugins' into feat/new_doc
CCherry07 Jun 28, 2024
e5539c8
feat: add plugins
CCherry07 Jun 28, 2024
7af139c
chore: command PackageManagerTabs
CCherry07 Jun 28, 2024
d6d789c
fix: add alias regex config (#126)
callqh Jul 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@
"documate",
"drei",
"Erkelost",
"farmup",
"feio",
"liuliudada",
"nocheck",
"nord",
"noreferrer",
"oblador",
"Pluggable",
"preact",
"Preprocess",
"PUFY",
"raxjs",
"Rolup",
"Rspack",
"rspress",
"Shiki",
"shikiji",
"shulandmimi",
"sveltejs",
"svgr",
"svgs",
"tailwindcss",
"tauri",
"Turbopack"
],
"editor.inlineSuggest.showToolbar": "always"
Expand Down
78 changes: 61 additions & 17 deletions docs/api/javascript-api.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PackageManagerTabs } from "../../src/theme/PackageManagerTabs";
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
import CodeBlock from "@theme/CodeBlock";
Expand All @@ -8,21 +9,7 @@ import CodeBlock from "@theme/CodeBlock";

Install the `@farmfe/core` package:

<>
<Tabs>
<TabItem value="npm" label="npm">
<CodeBlock>npm install @farmfe/core@latest</CodeBlock>
</TabItem>

<TabItem value="yarn" label="yarn">
<CodeBlock>yarn add @farmfe/core@latest</CodeBlock>
</TabItem>

<TabItem value="pnpm" label="pnpm">
<CodeBlock>pnpm add @farmfe/core@latest</CodeBlock>
</TabItem>
</Tabs>
</>
<PackageManagerTabs command="pnpm add @farmfe/core@latest" />

## Start

Expand All @@ -40,12 +27,68 @@ Basic example:
```javascript
import { start, logger } from "@farmfe/core";
try {
await start(options);
await start({
compilation: {
output: {
publicPath: "/dist"
},
input: {
index: "./base.html"
}
},
server: {
port: 6532,
hmr: {
path: "/__farm_hmr",
}
},
plugins: [
'@farmfe/plugin-react',
'@farmfe/plugin-sass'
],
});
} catch (error) {
logger.error(`Failed to start server:\n ${error.stack}`);
process.exit(1);
}
```

another way is use more deep api to start server:

```javascript
import {
createCompiler,
createDevServer,
resolveConfig
} from '@farmfe/core';

const resolveUserConfig = await resolveConfig({
compilation: {
output: {
publicPath: "/dist"
},
input: {
index: "./base.html"
}
},
server: {
port: 6532,
hmr: {
path: "/__farm_hmr",
}
},
plugins: [
'@farmfe/plugin-react',
'@farmfe/plugin-sass'
],
})

// create compiler
const compiler = await createCompiler(resolveUserConfig);
const server = await createDevServer(compiler, resolveUserConfig);
server.listen();
```

## Build
The build method is used to build for the production environment.

Expand Down Expand Up @@ -530,4 +573,5 @@ Basic example:
import { Compiler } from "@farmfe/core";
const compiler = new Compiler(config);
const result = compiler.modules();
```
```import { create } from "ts-node";

2 changes: 1 addition & 1 deletion docs/api/js-plugin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const myPlugin = () => {
name: 'my-plugin',
configResolved(resolvedConfig) {
// get resolved config
farmConfig = resolvedConfig;
resolvedConfig = farmConfig;
},
transform: {
filters: {
Expand Down
8 changes: 4 additions & 4 deletions docs/benchmark.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ pnpm benchmark

<!-- ![performance](/img/20231204223204.png) -->

<img style={{width: '100%',borderRadius: '8px', border: '2px solid #8f1a7f60'}} src="/img/20231204223204.png" />
<img style={{width: '100%',borderRadius: '8px'}} src="/img/20231204223204.png" />

### Benchmark of HMR

<!-- ![performance](/img/hmr-linux.png) -->

<img style={{width: '100%',borderRadius: '8px', border: '2px solid #8f1a7f60'}} src="/img/hmr-linux.png" />
<img style={{width: '100%',borderRadius: '8px'}} src="/img/hmr-linux.png" />

### Benchmark of Startup

<!-- ![performance](/img/startup-linux.png) -->

<img style={{width: '100%',borderRadius: '8px', border: '2px solid #8f1a7f60'}} src="/img/startup-linux.png" />
<img style={{width: '100%',borderRadius: '8px'}} src="/img/startup-linux.png" />

### Benchmark of Production Build

<!-- ![performance](/img/build-linux.png) -->

<img style={{width: '100%',borderRadius: '8px', border: '2px solid #8f1a7f60'}} src="/img/build-linux.png" />
<img style={{width: '100%',borderRadius: '8px'}} src="/img/build-linux.png" />
7 changes: 6 additions & 1 deletion docs/config/compilation-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,18 @@ export default defineConfig({
alias: {
"/@": path.join(process.cwd(), "src"),
stream$: "readable-stream",
"$__farm_regex:^/(utils)$": path.join(process.cwd(), "src/$1"),
},
},
},
});
```

alias is prefix replacement, for the above example `/@/pages` will be replaced by `/root/src/pages`. If you want an exact match, you can add `$`, for example `stream$` will only replace `stream`, but not `stream/xxx`.
alias is prefix replacement, for the above example `/@/pages` will be replaced by `/root/src/pages`.

If you want an exact match, you can add `$`, for example `stream$` will only replace `stream`, but not `stream/xxx`.

If you want to use regex, you can use `$__farm_regex:`, for example `$__farm_regex:^/(utils)$` will replace `/utils` to `/root/src/utils`.

#### `resolve. mainFields`

Expand Down
14 changes: 5 additions & 9 deletions docs/contribution.md → docs/contribution.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PackageManagerTabs } from '../src/theme/PackageManagerTabs';

# Contribution Guide

Thank you for your interest in contributing to Farm!. Before submitting your contribution, please make sure to take a moment and read through the following guidelines.
Expand Down Expand Up @@ -77,9 +79,7 @@ You can install them in the extension

Farm development is very simple. You only need to execute `pnpm bootstrap` in the root directory for development.

```bash
$ pnpm bootstrap
```
<PackageManagerTabs command="pnpm bootstrap" />

- use `pnpm bootstrap` to install dependencies and build core packages with series of initialization operations.

Expand All @@ -91,13 +91,9 @@ $ pnpm bootstrap

When you are developing node side code, the root directory executes pnpm start to debug the code in real time, and when you are developing rust side code, the root directory executes pnpm start:rs to debug the code in real time.

```ts
// node side
pnpm start
<PackageManagerTabs command="pnpm start // node side" />

// rust side
pnpm start:rs
```
<PackageManagerTabs command="pnpm start:rs // rust side" />

## Testing

Expand Down
25 changes: 12 additions & 13 deletions docs/features/css.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { PackageManagerTabs } from "../../src/theme/PackageManagerTabs";


# Css/Sass/Less
Farm support Css out of box, just import the css file:

Expand Down Expand Up @@ -29,14 +32,13 @@ You can configuring css modules by [`css.modules`](/docs/config/compilation-opti
Farm provide official sass, less, postcss plugins to support css pre-processor.

### Sass
Farm sass plugin is a Rust Plugin and use `sass-embeded`(we may migrate to [grass](https://github.com/connorskees/grass) in the future).
Farm sass plugin is a Rust Plugin and use `sass-embeded`(we may migrate to [grass](https://github.com/connorskees/grass) in the feature).

Steps to compile `sass/scss` modules in Farm.
1. Install dependencies
```sh
# npm or yarn or pnpm, choose your favorite package manager
pnpm add -D @farmfe/plugin-sass
```

<PackageManagerTabs command="pnpm add -D @farmfe/plugin-sass" />


2. Configure the plugin
```ts
Expand Down Expand Up @@ -90,10 +92,8 @@ export default defineConfig({
Farm less plugin is a Js Plugin. Steps to compile `less` modules in Farm.

1. Install dependencies
```sh
# npm or yarn or pnpm, choose your favorite package manager
pnpm add -D @farmfe/js-plugin-less
```

<PackageManagerTabs command="pnpm add -D @farmfe/js-plugin-less" />

2. Configure the plugin
```ts
Expand All @@ -117,10 +117,9 @@ To use sass with css modules, change the file name from `index.less` to `index.m
The Farm postcss plugin is a JS plugin. The steps to introduce postcss in Farm are as follows:

1. Install dependencies
```sh
# npm or yarn or pnpm, choose your favorite package manager
pnpm add -D @farmfe/js-plugin-postcss
```

<PackageManagerTabs command="pnpm add -D @farmfe/js-plugin-postcss" />


2. Configure the plugin
```ts
Expand Down
4 changes: 2 additions & 2 deletions docs/features/env.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Environment Variables and Modes

`Farm` distinguishes between `development` and `production` environments through `process.env.NODE_ENV`.
`Farm` distinguishes between `development` and `production` environments through `process.env.NODE\_ENV`.

In different environments, environment variables are replaced statically, so use static constants to represent environment variables instead of dynamic expressions.

Expand Down Expand Up @@ -61,4 +61,4 @@ export defineConfig({
})
```

For above config example, Farm will load `.env`, `.env.development`, etc from `<root>/env` dir.
For above config example, Farm will load `.env`, `.env.development`, etc from `<root>/env` dir.
52 changes: 52 additions & 0 deletions docs/frameworks/electron.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { PackageManagerTabs } from "../../src/theme/PackageManagerTabs";

# Electron

Create a `Electron` project based on `Farm`.

`Farm` provides two approaches to support creating `Electron` projects:
- Use the `create-farm` scaffold to create a scaffold project
- You can manually create a `Electron` project following the current documentation

### Creating a Electron Project

<PackageManagerTabs command="npm create farm@latest" />


Select `Electron` template in `Select Framework`

After selecting `Electron`, you can continue to select all sub templates already supported by `Farm`

```ts
- React
- Vue
- Preact
- Svelte
- Solid
```

You can choose the framework you want to use to run on electron, farm wrote electron js plugin

such as react template

```ts
import { defineConfig } from '@farmfe/core';
import electron from '@farmfe/js-plugin-electron';

export default defineConfig({
plugins: [
'@farmfe/plugin-react',
electron({
main: {
input: 'electron/main.ts',
},
preload: {
input: 'electron/preload.ts',
},
}),
]
});

```

For more example details: [Electron Example](https://github.com/farm-fe/farm/tree/main/examples/Electron)
43 changes: 43 additions & 0 deletions docs/frameworks/lit.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { PackageManagerTabs } from "../../src/theme/PackageManagerTabs";

# Lit

Create a `Lit` project based on `Farm`.

`Farm` provides two approaches to support creating `Lit` projects:
- Use the `create-farm` scaffold to create a scaffold project
- You can manually create a `Lit` project following the current documentation

### Creating a Lit Project

<PackageManagerTabs command="npm create farm@latest" />


Select `Lit` template in `Select Framework`

If you use lit then we need to configure the decorator

```javascript title="farm.config.ts"
import { defineConfig } from '@farmfe/core';

export default defineConfig({
compilation: {
presetEnv: false,
script: {
plugins: [],
target: 'es2022',
parser: {
tsConfig: {
decorators: true,
dts: false,
noEarlyErrors: false,
tsx: false
}
}
}
}
});

```

For more example details: [React Example](https://github.com/farm-fe/farm/tree/main/examples/Lit)
Loading