PageSourceSearch

https://farm-nightly.netlify.app/assets/js/f262c6e3.4d40fc4c.js

js farm-nightly.netlify.app collected 2026-10-03 10:45:16 UTC 6,782 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkfarm_docs=self.webpackChunkfarm_docs||[]).push([[6152],{57409:(e,n,i)=>{i.r(n),i.d(n,{assets:()=>d,contentTitle:()=>c,default:()=>f,frontMatter:()=>s,metadata:()=>t,toc:()=>l});var o=i(49214),r=i(36906);const s={},c="Configuring Farm",t={id:"config/configuring-farm",title:"Configuring Farm",description:"Config File Spec",source:"@site/docs/config/configuring-farm.md",sourceDirName:"config",slug:"/config/configuring-farm",permalink:"/docs/config/configuring-farm",draft:!1,unlisted:!1,editUrl:"https://github.com/farm-fe/farm-fe.github.io/tree/main/docs/config/configuring-farm.md",tags:[],version:"current",frontMatter:{},sidebar:"configSidebar",next:{title:"Compiler Options",permalink:"/docs/config/compilation-options"}},d={},l=[{value:"Config File Spec",id:"config-file-spec",level:2},{value:"Loading Ts Config File",id:"loading-ts-config-file",level:2},{value:"Examples",id:"examples",level:2},{value:"Input and Output",id:"input-and-output",level:3},{value:"Dev Server Port",id:"dev-server-port",level:3},{value:"Disable Default Optimizations",id:"disable-default-optimizations",level:3}];function a(e){const n={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(n.header,{children:(0,o.jsx)(n.h1,{id:"configuring-farm",children:"Configuring Farm"})}),"\n",(0,o.jsx)(n.h2,{id:"config-file-spec",children:"Config File Spec"}),"\n",(0,o.jsxs)(n.p,{children:["By default, Farm reads the configuration from the ",(0,o.jsx)(n.code,{children:"farm.config.ts|js|mjs"})," file in the project root directory, an example configuration file:"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-ts",metastring:'title="farm.config.ts" {5-7}',children:'import { defineConfig } from "@farmfe/core";\n\nexport default defineConfig({\n  root: process.cwd(), // compiled root directory\n  // compile options\n  compilation: {\n    //...\n  },\n  // Dev Server options\n  server: {\n    hmr: true,\n    //...\n  },\n  // plugin configuration\n  plugins: [],\n});\n'})}),"\n",(0,o.jsx)(n.p,{children:"For config options details, refer to:"}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.a,{href:"/docs/config/compilation-options",children:(0,o.jsx)(n.code,{children:"Compiler Options"})}),": Configuring compiler options(",(0,o.jsx)(n.code,{children:"compilation"})," field), like ",(0,o.jsx)(n.code,{children:"input"}),", ",(0,o.jsx)(n.code,{children:"output"}),", ",(0,o.jsx)(n.code,{children:"css compilation"}),", ",(0,o.jsx)(n.code,{children:"bundling rules"})," and so on."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.a,{href:"/docs/config/dev-server",children:(0,o.jsx)(n.code,{children:"Dev Server Options"})}),": Configuring dev server options(",(0,o.jsx)(n.code,{children:"server"})," field), like ",(0,o.jsx)(n.code,{children:"port"}),", ",(0,o.jsx)(n.code,{children:"host"}),", ",(0,o.jsx)(n.code,{children:"protocol"})," and so on."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.a,{href:"/docs/config/shared",children:(0,o.jsx)(n.code,{children:"Shared Options"})}),": Configuring shared options between ",(0,o.jsx)(n.code,{children:"compiler options"})," and ",(0,o.jsx)(n.code,{children:"dev server options"}),", like ",(0,o.jsx)(n.code,{children:"root"}),", ",(0,o.jsx)(n.code,{children:"env"})," and so on."]}),"\n"]}),"\n",(0,o.jsx)(n.admonition,{type:"note",children:(0,o.jsxs)(n.p,{children:["You can also use ",(0,o.jsx)(n.code,{children:"farm start/build -c my-config.ts"})," to use a custom file as config file."]})}),"\n",(0,o.jsx)(n.h2,{id:"loading-ts-config-file",children:"Loading Ts Config File"}),"\n",(0,o.jsxs)(n.p,{children:["Farm support load ts config file like ",(0,o.jsx)(n.code,{children:"farm.config.ts"})," out of box. Farm will bundle ",(0,o.jsx)(n.code,{children:"farm.config.ts"})," and it's local ts dependencies into ",(0,o.jsx)(n.code,{children:"farm-config.xxx.mjs"})," file first and load it from disk. Because Farm compiles the ",(0,o.jsx)(n.code,{children:"farm.config.ts"})," into ",(0,o.jsx)(n.code,{children:"mjs"})," file, you ",(0,o.jsx)(n.strong,{children:"CAN NOT"})," use ",(0,o.jsx)(n.code,{children:"__dirname"})," or ",(0,o.jsx)(n.code,{children:"__filename"})," in your ",(0,o.jsx)(n.code,{children:"farm.config.ts"}),", use ",(0,o.jsx)(n.code,{children:"import.meta.url"})," instead."]}),"\n",(0,o.jsxs)(n.p,{children:["Or you can use ",(0,o.jsx)(n.code,{children:"farm.config.mjs"})," or ",(0,o.jsx)(n.code,{children:"farm.config.cjs"})," with ",(0,o.jsx)(n.code,{children:"@type"}
1)," to support types avoid bundling ",(0,o.jsx)(n.code,{children:"farm.config.ts"}),":"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",metastring:'title="farm.config.mjs"',children:"/**\n * @type {import('@farmfe/core').UserConfig}\n */\nexport default {\n  // ...\n}\n"})}),"\n",(0,o.jsx)(n.h2,{id:"examples",children:"Examples"}),"\n",(0,o.jsx)(n.h3,{id:"input-and-output",children:"Input and Output"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-ts",metastring:'title="farm.config.ts" {5-7}',children:"import { defineConfig } from \"@farmfe/core\";\n\nexport default defineConfig({\n  // compile options\n  compilation: {\n    input: {\n      index: './src/index.html',\n      about: './src/about.html',\n    },\n    output: {\n      path: 'build',\n      publicPath: process.env.NODE_ENV === 'production' ? 'https://my-cdn.com' : '/'\n    }\n  },\n});\n"})}),"\n",(0,o.jsxs)(n.p,{children:["In above example, we configured ",(0,o.jsx)(n.code,{children:"./src/index.html"})," and ",(0,o.jsx)(n.code,{children:"./src/about.html"})," as input, then output the compiled resources to ",(0,o.jsx)(n.code,{children:"build"})," dir."]}),"\n",(0,o.jsx)(n.h3,{id:"dev-server-port",children:"Dev Server Port"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-ts",metastring:'title="farm.config.ts" {5-7}',children:'import { defineConfig } from "@farmfe/core";\n\nexport default defineConfig({\n  server: {\n    port: 9801\n  }\n});\n'})}),"\n",(0,o.jsx)(n.h3,{id:"disable-default-optimizations",children:"Disable Default Optimizations"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-ts",metastring:'title="farm.config.ts" {5-7}',children:'import { defineConfig } from "@farmfe/core";\n\nexport default defineConfig({\n  // compile options\n  compilation: {\n    lazyCompilation: false,\n    persistentCache: false,\n    minify: false,\n    treeShake: false\n  },\n});\n'})})]})}function f(e={}){const{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.