---
title: "Configuring Farm"
locale: "en"
version: "1.x"
canonicalUrl: "https://farmfe.org/docs/1.x/config/configuring-farm"
publicationStatus: "prerelease"
---

<a id="configuring-farm"></a>
# Configuring Farm


<a id="config-file-spec"></a>
## Config File Spec


By default, Farm reads the configuration from the ` farm.config.ts|js|mjs ` file in the project root directory, an example configuration file:


```ts
import { defineConfig } from "@farmfe/core";

export default defineConfig({
  root: process.cwd(), // compiled root directory
  // compile options
  compilation: {
    //...
  },
  // Dev Server options
  server: {
    hmr: true,
    //...
  },
  // plugin configuration
  plugins: [],
});
```


For config options details, refer to:


- [` Compiler Options `](</docs/config/compilation-options>): Configuring compiler options(` compilation ` field), like ` input `, ` output `, ` css compilation `, ` bundling rules ` and so on.
- [` Dev Server Options `](</docs/config/dev-server>): Configuring dev server options(` server ` field), like ` port `, ` host `, ` protocol ` and so on.
- [` Shared Options `](</docs/config/shared>): Configuring shared options between ` compiler options ` and ` dev server options `, like ` root `, ` env ` and so on.



> [!NOTE]
> note
> 
> You can also use ` farm start/build -c my-config.ts ` to use a custom file as config file.



<a id="loading-ts-config-file"></a>
## Loading Ts Config File


Farm support load ts config file like ` farm.config.ts ` out of box. Farm will bundle ` farm.config.ts ` and it's local ts dependencies into ` farm-config.xxx.mjs ` file first and load it from disk. Because Farm compiles the ` farm.config.ts ` into ` mjs ` file, you **CAN NOT** use ` __dirname ` or ` __filename ` in your ` farm.config.ts `, use ` import.meta.url ` instead.


Or you can use ` farm.config.mjs ` or ` farm.config.cjs ` with ` @type ` to support types avoid bundling ` farm.config.ts `:


```js
/**
 * @type {import('@farmfe/core').UserConfig}
 */
export default {
  // ...
}
```


<a id="examples"></a>
## Examples


<a id="input-and-output"></a>
### Input and Output


```ts
import { defineConfig } from "@farmfe/core";

export default defineConfig({
  // compile options
  compilation: {
    input: {
      index: './src/index.html',
      about: './src/about.html',
    },
    output: {
      path: 'build',
      publicPath: process.env.NODE_ENV === 'production' ? 'https://my-cdn.com' : '/'
    }
  },
});
```


In above example, we configured ` ./src/index.html ` and ` ./src/about.html ` as input, then output the compiled resources to ` build ` dir.


<a id="dev-server-port"></a>
### Dev Server Port


```ts
import { defineConfig } from "@farmfe/core";

export default defineConfig({
  server: {
    port: 9801
  }
});
```


<a id="disable-default-optimizations"></a>
### Disable Default Optimizations


```ts
import { defineConfig } from "@farmfe/core";

export default defineConfig({
  // compile options
  compilation: {
    lazyCompilation: false,
    persistentCache: false,
    minify: false,
    treeShake: false
  },
});
```
