Farm Build Tool — Agent Guide
Farm is an extremely fast Vite-compatible web build tool written in Rust.
Official site: https://farmfe.org | Package: @farmfe/core | Repo: farm-fe/farm
Reference Index
Detailed documentation is split into focused reference files under references/:
| File |
Contents |
references/config.md |
Config file setup, shared options, all compilation.* options, all server.* options |
references/cli.md |
CLI commands (start, build, watch, preview, clean) and all flags |
references/plugins.md |
Using plugins (Rust, JS, Vite/Rollup, SWC, Runtime) + official plugins table |
references/features.md |
Quick start, CSS, TypeScript/JSX, env vars, assets, library mode, SSR, HMR, lazy compilation, persistent cache |
references/javascript-api.md |
@farmfe/core JS API — start/build/watch/preview/clean, Compiler, Server, loadEnv |
references/js-plugin-api.md |
Writing JS plugins — all hooks, filters structure, code examples |
references/writing-plugins.md |
Authoring custom plugins — scaffolding, JS plugin structure, Rust plugin structure, hooks, publishing |
references/recipes.md |
Common patterns, framework quick-configs (React/Vue/Svelte/Electron), troubleshooting |
Quick Orientation
Create a Project
pnpm create farm@latest
# or with a template:
pnpm create farm my-app --template react
Templates: vanilla, react, vue3, vue2, svelte, solid, preact, lit, nestjs, tauri, electron.
Minimal Config
import { defineConfig } from '@farmfe/core';
export default defineConfig({
plugins: ['@farmfe/plugin-react'], // Rust plugin by package name
compilation: {
input: { index: './index.html' },
output: { targetEnv: 'browser-es2017' },
},
server: { port: 9000 },
});
Key Rules
- Config file:
farm.config.ts|js|mjs — do not use __dirname/__filename; use import.meta.url.
- Rust plugins →
plugins: ['package-name'] or ['package-name', optionsObject].
- Vite/Rollup plugins →
vitePlugins: [plugin()], not plugins.
- JS plugin hooks must declare
filters (regex arrays) for performance.
resolve.symlinks: true is required when using pnpm.
targetEnv: 'library' enables library mode with format: ['esm', 'cjs'] array support.
Dev/Prod Defaults
| Option |
Development |
Production |
lazyCompilation |
✅ enabled |
❌ disabled |
persistentCache |
✅ enabled |
✅ enabled |
minify |
❌ disabled |
✅ enabled |
treeShaking |
❌ disabled |
✅ enabled |
presetEnv |
❌ disabled |
✅ enabled |
css.transformToScript |
✅ enabled |
❌ disabled |
1---2name: farmfe-guide3description: Comprehensive Farm build-tool reference for AI agents. Use when writing or reviewing farm.config.ts, adding/configuring plugins, troubleshooting builds, implementing SSR or library mode, using the JavaScript API, writing Farm JS/Rust plugins, or authoring custom plugins from scratch. Covers all config options, official plugins, CLI commands, key features, and plugin authoring sourced from website/docs.4license: MIT5---67# Farm Build Tool — Agent Guide89Farm is an extremely fast Vite-compatible web build tool written in Rust. 10Official site: https://farmfe.org | Package: `@farmfe/core` | Repo: `farm-fe/farm`1112---1314## Reference Index1516Detailed documentation is split into focused reference files under `references/`:1718| File | Contents |19|------|----------|20| [`references/config.md`](references/config.md) | Config file setup, shared options, all `compilation.*` options, all `server.*` options |21| [`references/cli.md`](references/cli.md) | CLI commands (`start`, `build`, `watch`, `preview`, `clean`) and all flags |22| [`references/plugins.md`](references/plugins.md) | Using plugins (Rust, JS, Vite/Rollup, SWC, Runtime) + official plugins table |23| [`references/features.md`](references/features.md) | Quick start, CSS, TypeScript/JSX, env vars, assets, library mode, SSR, HMR, lazy compilation, persistent cache |24| [`references/javascript-api.md`](references/javascript-api.md) | `@farmfe/core` JS API — `start/build/watch/preview/clean`, `Compiler`, `Server`, `loadEnv` |25| [`references/js-plugin-api.md`](references/js-plugin-api.md) | Writing JS plugins — all hooks, `filters` structure, code examples |26| [`references/writing-plugins.md`](references/writing-plugins.md) | **Authoring custom plugins** — scaffolding, JS plugin structure, Rust plugin structure, hooks, publishing |27| [`references/recipes.md`](references/recipes.md) | Common patterns, framework quick-configs (React/Vue/Svelte/Electron), troubleshooting |2829---3031## Quick Orientation3233### Create a Project3435```bash36pnpm create farm@latest37# or with a template:38pnpm create farm my-app --template react39```4041Templates: `vanilla`, `react`, `vue3`, `vue2`, `svelte`, `solid`, `preact`, `lit`, `nestjs`, `tauri`, `electron`.4243### Minimal Config4445```ts title="farm.config.ts"46import { defineConfig } from '@farmfe/core';4748export default defineConfig({49 plugins: ['@farmfe/plugin-react'], // Rust plugin by package name50 compilation: {51 input: { index: './index.html' },52 output: { targetEnv: 'browser-es2017' },53 },54 server: { port: 9000 },55});56```5758### Key Rules5960- Config file: `farm.config.ts|js|mjs` — do **not** use `__dirname`/`__filename`; use `import.meta.url`.61- Rust plugins → `plugins: ['package-name']` or `['package-name', optionsObject]`.62- Vite/Rollup plugins → `vitePlugins: [plugin()]`, **not** `plugins`.63- JS plugin hooks **must** declare `filters` (regex arrays) for performance.64- `resolve.symlinks: true` is required when using pnpm.65- `targetEnv: 'library'` enables library mode with `format: ['esm', 'cjs']` array support.6667### Dev/Prod Defaults6869| Option | Development | Production |70|--------|:-----------:|:----------:|71| `lazyCompilation` | ✅ enabled | ❌ disabled |72| `persistentCache` | ✅ enabled | ✅ enabled |73| `minify` | ❌ disabled | ✅ enabled |74| `treeShaking` | ❌ disabled | ✅ enabled |75| `presetEnv` | ❌ disabled | ✅ enabled |76| `css.transformToScript` | ✅ enabled | ❌ disabled |