Skip to main content
FarmFarm
Version: 2.x (Latest)
On this page

Compiler Options

By default, Farm reads the configuration from farm.config.ts, farm.config.js, farm.config.cjs, farm.config.mjs, farm.config.cts, or farm.config.mts in the project root directory. An example configuration file:

farm.config.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: [],
});

This document only covers details compilation options. For server or shared options, refer to server or shared

Compilation options - compilation

All compilation-related configuration is under the compilation field.

input

  • type: Record<string, string>

The entry point for the project. Input files can be html, ts/js/tsx/jsx, css or other files supported by plugins.

tsx
import { defineConfig } from "@farmfe/core";

export default defineConfig({
  compilation: {
    input: {
      index: "./index.html",
      about: "./about.html",
    },
  },
  // ..
});

output

  • type: OutputOptions
ts
interface OutputOptions {
  // After partial bundling, the file name configuration of the resource where the entry file is located
  entryFilename?: string;
  // After partial bundling, other resources except the entry resource input file name configuration
  filename?: string;
  // output directory
  path?: string;
  // public path: resource loading prefix
  publicPath?: string;
  // Static resource file name configuration
  assetsFilename?: string;
  // Target execution environment. Versioned targets select Farm's production compatibility presets.
  targetEnv?: 'browser' | 'node' | 'node16' | 'node-legacy' | 'node-next' | 'browser-legacy' | 'browser-es2015' | 'browser-es2017' | 'browser-esnext' | 'library';
  // output module format, supports a single format or an array of formats (array only when targetEnv is 'library')
  format?: 'cjs' | 'esm' | 'umd' | 'iife' | 'system' | 'amd' | ('cjs' | 'esm' | 'umd' | 'iife' | 'system' | 'amd')[];
  // Whether to print file size of output files
  showFileSize?: boolean;
  // output ascii only
  asciiOnly?: boolean;
  // external globals name mapping, only works when targetEnv is 'browser' or 'library' with format 'iife' or 'umd'
  externalGlobals?: Record<string, string>;
  // global name for umd/iife format
  name?: string;
}

output.entryFilename

  • default: "[entryName].[ext]"

Configure the filename of the entry resource: you can use placeholders such as [entryName]. All placeholders are as follows:

  • [entryName]: entry name, for example, for input: { index: "./index.html" }, [entryName] is index
  • [resourceName]: The name of the resource, usually a unique hash value generated internally by Farm.
  • [contentHash]: The content hash of the resource.
  • [ext]: The extension of the resource, js for js/jsx/ts/tsx, css for css/scss/less.

output.filename

  • Default value: "[resourceName].[ext]"

After partial bundling, other resource file names except the resources configured by entryFilename. All placeholders are as follows:

  • [resourceName]: The name of the resource, usually a unique hash value generated internally by Farm.
  • [contentHash]: The content hash of the resource.
  • [ext]: The extension of the resource, js for js/jsx/ts/tsx, css for css/scss/less.

output.path

  • default: "dist"

directory of output resources

output.publicPath

  • Default value: "/"

The resource url load prefix. For example URL https://xxxx, or a absolute path /xxx/. For example config:

farm.config.ts
// ...

export default defineConfig({
  compilation: {
    output: {
      publicPath: process.env.NODE_ENV === 'production' ? 'https://cdn.com' : '/'
    }
  }
  // ...
});

When building for production, the injected resources url would be https://cdn.com/index-s2f3.s14dqwa.js. For example, in your output html, all <script> and <link> would be:

html
<html>
  <head>
    <!-- ... -->
    <link href="https://cdn.com/index-a23e.s892s1.css" />
  </head>
  <body>
    <!-- ... -->
    <script src="https://cdn.com/index-s2f3.s14dqwa.js"></script>
  </body>
</html>

and when loading dynamic scripts and css, the dynamic fetched resources url would also be: https://cdn.com/<asset-path>

output.assetsFilename

  • Default value: "[resourceName].[ext]"

The filename configuration for static resource output, the placeholder is the same as output.filename.

output.targetEnv

  • default: "browser" for application builds

Configure the execution environment of the product. Set this explicitly to "library" when building package output instead of an application. In production builds, versioned targets select Farm's compatibility presets, including browser syntax downgrade and preset-env behavior where applicable. The supported targetEnvs are below:

Targeting browser:

  • browser-es2017: Compiling the project to browsers that support async await natively.
  • browser-es2015: Compiling the project to browsers that support es6 features natively.
  • browser-legacy: Compile the project to ES5, for example, IE9. Note that this may introduce lots of polyfills which makes production size larger. Make sure you really need to support legacy browsers like IE9.
  • browser-esnext: Compile the project to latest modern browsers, no polyfill will be injected.
  • browser: Browser output without versioned downgrade presets.

Targeting node:

  • node16: Compile the project to Node 16.
  • node-legacy: Compile the project to Node 10.
  • node-next: Compile the project to latest Node Version, no polyfill will be injected.
  • node: Node output without versioned downgrade presets.

Targeting library:

  • library: Build as a library. When targetEnv is library, you can set format to an array of formats (e.g. ['esm', 'cjs']) to produce multiple output bundles in one build.

output.format

  • default: "esm"

Configure the output module format. Supported values: "esm", "cjs", "umd", "iife", "system", "amd".

When output.targetEnv is "library", you can pass an array of formats to generate multiple outputs in a single build:

ts
export default defineConfig({
  compilation: {
    output: {
      targetEnv: 'library',
      format: ['esm', 'cjs'],
    },
  },
});

output.libraryBundleType

  • type: "single-bundle" | "multiple-bundle" | "bundle-less"
  • default: "single-bundle"

This field controls the library bundling strategy when output.targetEnv is "library":

  • single-bundle: one output bundle per format. This mode only supports a single entry.
  • multiple-bundle: each entry produces its own output bundle and shared chunks may be extracted.
  • bundle-less: each source module is emitted independently, preserving the source structure.

output.clean

  • default: true

Whether to clean output.path before emitting files.

output.showFileSize

  • default: true

Whether to print file size information for the final output files after build.

output.asciiOnly

  • default: false

Whether to escape non-ASCII characters in the output to ASCII-safe sequences.

output.externalGlobals

  • default: {}

Map external module names to global variable names. For example, { "react": "React" } means import * as React from 'react' will access React from window.React at runtime.

output.name

  • default: "__farm_global__"

The global variable name used for umd/iife format output. If not set, the default __farm_global__ will be used.

resolve

  • type: ResolveOptions
ts
interface ResolveOptions {
  extensions?: string[];
  alias?: Record<string, string> | Array<{ find: string | RegExp; replacement: string }>;
  mainFields?: string[];
  conditions?: string[];
  symlinks?: boolean;
  strictExports?: boolean;
  autoExternalFailedResolve?: boolean;
  dedupe?: string[];
}

resolve.extensions

  • default: ["tsx", "mts", "cts", "ts", "jsx", "mjs", "js", "cjs", "json", "html", "css"]

Configure the suffix when parsing dependencies. For example, when parsing ./index, if it is not resolved, the suffix parsing will be automatically added, such as trying ./index.tsx, ./index.css, etc.

resolve.alias

  • Default value: {}

Configure parsing alias, example:

ts
export default defineConfig({
  compilation: {
    resolve: {
      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.

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

You can also use the array form for more control:

ts
export default defineConfig({
  compilation: {
    resolve: {
      alias: [
        { find: '/@', replacement: path.join(process.cwd(), 'src') },
        { find: /^\/(utils)$/, replacement: path.join(process.cwd(), 'src/$1') },
      ],
    },
  },
});

resolve.mainFields

  • default: ["exports", "browser", "module", "main"]

When parsing dependencies under node_modules, the fields and order configured in mainFields will be parsed from package.json. For package.json

json
{
  "name": "package-a",
  "module": "es/index.js",
  "main": "lib/index.js"
}

Will use es/index.js first (if the path exists), and will continue to search backwards if it does not exist.

resolve.conditions

  • default: ["development", "production", "module"]

The conditions field used when resolving package exports/imports in package.json.

  • default: true

When parsing a file, whether to track the real directory corresponding to the symlink, and start parsing the next dependency from the real directory. If pnpm is used to manage dependencies, this option must be configured as true.

resolve.strictExports

  • default: false

Whether to strictly follow the exports defined in exports in package.json. If set to true, when exports is defined in package.json, but exports does not define the corresponding export, an error will be reported directly. If set to false, it will continue to try other entries according to mainFields.

resolve.autoExternalFailedResolve

  • default: false

If a module cannot be resolved, automatically mark it as external instead of raising an error.

resolve.dedupe

  • default: []

Configure a list of module names that should always be resolved to the same copy from the project root, even if multiple versions exist in the dependency tree. Useful for avoiding duplicated packages like react.

define

  • Default value: {}

Global variable injection, the configured variable name and value will be injected into the product at compile time. Farm injects process.env.NODE_ENV and some variables used by Farm itself such as FARM_HMR_PORT by default

ts
export default defineConfig({
  compilation: {
    define: {
      MY_VAR: 123,
    },
  },
});

external

  • default: []
  • type: (string | Record<string, string>)[]

Configure the imports that are external, and the imports that are external will not appear in the compiled product. However, the corresponding import statement will not be deleted. You need to customize how to deal with external, otherwise an error will be reported at runtime. If targetEnv is an external module under node, it will automatically try to require the module.

It needs to be configured in a regular way, for example:

ts
export default defineConfig({
  compilation: {
    external: ["^stream$", { jquery: "Jquery" }],
  },
});

externalNodeBuiltins

  • default: true

External module.builtinModules or not, by default, all builtin modules like fs will be external. You can also set externalNodeBuiltins as array to specify the modules to external manually:

ts
export default defineConfig({
  compilation: {
    externalNodeBuiltins: ["^stream$"],
  },
});

mode

  • default: development for start, watch commands, production for build commands

Configure the compilation mode. In order to optimize the performance during development, if there is no manual configuration of production optimization related options (minify, tree shake, etc.), the production environment optimization such as compression and tree shake will be disabled by default under development. In production mode enabled.

runtime

Configure Farm runtime capabilities. The types are as follows:

ts
interface FarmRuntimeOptions {
  runtime?: {
    path: string;
    plugins?: string[];
    swcHelpersPath?: string;
    isolate?: boolean;
  };
}

runtime.path

  • Default value: The path of Farm's built-in runtime

Customize a Runtime to replace Farm's built-in Runtime.

runtime.plugins

  • Default value: The path of Farm's built-in runtime-plugin-hmr

Configure the Runtime plug-in, through the Runtime plug-in, you can intervene in Runtime behavior, such as module loading, resource loading, etc. For details, refer to Runtime Plugin API.

runtime.swcHelpersPath

  • default: undefined

Customize the path of @swc/helpers. It is not recommended to set this option unless you have a specific need to override the default helpers resolution.

runtime.namespace

  • default: name field of project package.json

Configure the namespace of Farm Runtime to ensure that the execution of different products under the same window or global can be isolated from each other. By default, the name field of the project package.json is used as the namespace.

runtime.isolate

  • default: false

By default, runtime files in html are written inline. If you want to reduce the size of the html file by popping it up as a separate file, then you can set this attribute to true. If set to true, the farm entry script will be emitted as a separate file.

assets

assets.include

  • default: []

Additional file suffixes that are regarded as static resources, such as the following example, txt will be regarded as posture resources, and will be treated as static resources when importing txt files:

ts
export default defineConfig({
  compilation: {
    assets: {
      include: ["txt"],
    },
  },
});

assets.publicDir

  • default: top-level publicDir, resolved from the project root

Override the public assets directory for the compiler. In most projects, use the top-level publicDir shared option instead so the dev server and build pipeline stay in sync.

assets.mode

Controls how static assets are emitted for browser or Node-style output. Most projects should leave this unset and configure output.targetEnv instead.

script

script.target

  • Default value: esnext (dynamically adjusted according to the iteration of Farm)

Configure Farm to parse the AST of js/jsx/ts/tsx and support the ES syntax version when generating code. Possible values: es5, es6, es2015 - es2023, esnext

script.parser

  • default: same as SWC

Configure the behavior of SWC when parsing AST, configuration item reference: https://swc.rs/docs/configuration/compilation#jscparser

script.plugins

  • default: []

Configure the swc plugin array, each item of the array contains three fields:

  • name: the package name of the swc plugin
  • options: Configuration items passed to swc plugin
  • filters: Which modules to execute the plug-in, must be configured, support resolvedPaths and moduleTypes these two filter items, if both are specified at the same time, take the union.

An example of a configuration that supports JSX for a Vue project is as follows. For Vue SFC support, register the current Rust plugin @farmfe/plugin-vue:

ts
import vue from "@farmfe/plugin-vue";

/**
 * @type {import('@farmfe/core').UserConfig}
 */
export default {
  compilation: {
    script: {
      plugins: [
        {
          name: "swc-plugin-vue-jsx",
          options: {
            transformOn: true,
            optimize: true,
          },
          filters: {
            // resolvedPaths: [".+"]
            moduleTypes: ["tsx", "jsx"],
          },
        },
      ],
    },
  },
  plugins: [vue()],
};

script.decorators

ts
export interface DecoratorsConfig {
  legacyDecorator: boolean;
  decoratorMetadata: boolean;
  /**
   * The version of the decorator proposal to use. 2021-12 or 2022-03
   * @default 2021-12
   */
  decoratorVersion: "2021-12" | "2022-03" | null;
  /**
   * @default []
   */
  includes: string[];
  /**
   * @default ["node_modules/"]
   */
  excludes: string[];
}

It's recommended to use default decorators configuration of Farm, unless you want to improve performance, you can set includes and excludes.

Options:

  • legacyDecorator: default to true. Using legacy decorator proposal.
  • decoratorMetadata: default to false. You have to set legacyDecorator to false if you want to set it to true.
  • decoratorVersion: default to '2021-12', proposal version. The value is 2021-12 or 2022-03.
  • includes: default to []. If you want to include modules that are excluded, you can set this option. Regex supported.
  • excludes: default to ['node_modules/']. Modules under these paths are ignored when transform decorators. Regex supported

script.nativeTopLevelAwait

  • default: false

Keep top-level await in the output entry file. Useful when building a library that needs to preserve async initialization.

script.importNotUsedAsValues

  • default: "remove"

Controls how type-only imports are handled. Mirrors TypeScript's importsNotUsedAsValues. Possible values:

  • "remove": remove type-only imports entirely (default).
  • "preserve": keep all imports.
  • { preserve: string[] }: an object with a preserve array of regex strings. Modules matching any regex are treated as "preserve"; all others are "remove".

css

css.modules

Configure Farm CSS Modules.

ts
interface FarmCssModulesConfig {
  // Configure which paths will be processed as css modules, using regular strings
  // defaults to `.module.css` or `.module.scss` or `.module.less`
  paths?: string[];
  // configure the generated css class name, the default is `[name]-[hash]`
  indentName?: string;
  // configure the local variable name conversion for css modules
  localsConversion?: 'asIs' | 'lowerCamel' | 'upperCamel' | 'snake';
}
css.modules.paths
  • default: ["\\.module\\.(css|scss|sass|less)"]

Configure which paths correspond to modules that will be treated as CSS Modules. A regular string needs to be configured. Defaults to files ending in .module.(css|scss|sass|less).

css.modules.indentName
  • default: [name]-[hash]

Configure the generated CSS Modules class name, the default is [name]-[hash], [name], [hash] are placeholders (also all currently supported placeholders). [name] means the original class name, [hash] means the hash of the modified css file id.

css.modules.localsConversion
  • default: "asIs"

Configure how CSS Modules local variable names are converted when exported to JS. Possible values:

  • "asIs": no conversion, keep the original class name.
  • "lowerCamel": convert to lower camelCase, e.g. foo-bar → fooBar.
  • "upperCamel": convert to upper CamelCase, e.g. foo-bar → FooBar.
  • "snake": convert to snake_case, e.g. foo-bar → foo_bar.

css.prefixer

Configure CSS compatibility prefixes, such as -webkit-.

ts
interface FarmCssPrefixer {
  targets?: string[] | string | BrowserTargetsRecord;
}

type BrowserTargetsRecord = Partial<
  Record<
    | "chrome"
    | "opera"
    | "edge"
    | "firefox"
    | "safari"
    | "ie"
    | "ios"
    | "android"
    | "node"
    | "electron",
    string
  >
> & { [key: string]: string };
css.prefixer.targets
  • Default value: undefined

Configure which target browsers or browser versions to enable, for example:

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

export default defineConfig({
  compilation: {
    css: {
      prefixer: {
        targets: ["last 2 versions", "Firefox ESR", "> 1%", "ie >= 11"],
      },
    },
  },
});

css.transformToScript

  • default: true in development, false in production

Whether to transform CSS modules to JS scripts. When true, each CSS module will be converted to a script that injects the CSS into the document head via document.createElement('style'). This enables per-module HMR in development. In production builds, CSS is typically kept as standalone CSS files.

html

html.base

  • Default value: undefined

All HTML entries will inherit html.base, for details, refer to Guide - HTML

sourcemap

  • default: true

Configure whether to enable sourcemap, optional configuration items and descriptions are as follows:

  • true: Only generate sourcemap for files not under node_modules, and generate a separate sourcemap file
  • false: turn off sourcemap
  • inline: Only generate sourcemap for files not under node_modules, and inline sourcemap into the product, do not generate a separate file
  • all: generate sourcemap for all files, and generate a separate sourcemap file
  • all-inline: Generate sourcemaps for all files, and inline sourcemaps into the product, do not generate separate files

partialBundling

Configure the behavior of Farm's partial bundling. For details, please refer to Partial Bundling

ts
export interface FarmPartialBundlingConfig {
  targetConcurrentRequests?: number;
  targetMinSize?: number;
  targetMaxSize?: number;
  groups?: {
    name: string;
    test: string[];
    groupType?: "mutable" | "immutable";
    resourceType?: "all" | "initial" | "async";
  }[];
  enforceResources?: {
    name: string;
    test: string[];
  }[];
  enforceTargetConcurrentRequests?: boolean;
  enforceTargetMinSize?: boolean;
  immutableModules?: string[];
}

partialBundling.targetConcurrentRequests

  • default: 25

Farm tries to generate resource numbers as closer as possible to this config value for initial resource loading or a dynamic resource loading.

partialBundling.targetMinSize

  • default: 20 * 1024 bytes, 20 KB

The minimum size of each generated resources before minify and gzip. Note that targetMinSize will not be satisfied if ModuleBucket's size is less than targetMinSize, ModuleBucket will be given priority. Config enforceTargetMinSize can be used to enforce size.

partialBundling.targetMaxSize

  • default: 1500 * 1024 bytes, 1500 KB

The maximum size of generated resources before minify and gzip.

partialBundling.groups

  • default: []

A group of modules that should be placed together. Note that this group config is only a hit to the compiler that these modules should be placed together, it may produce multiple resources, if you want to enforce modules in the same resource, you should use enforceResources.

Options for each item:

  • name: Name of this group.
  • test: Regex array to match the modules which are in this group.
  • groupType: mutable or immutable, this group only applies to the specified type of modules.
  • resourceType: all, initial or async, this group only applies to the specified type of resources.
farm.config.ts
export default defineConfig({
  compilation: {
    partialBundling: {
      groups: [
        {
          name: "vendor-react",
          test: ["node_modules/"],
        },
      ],
    },
  },
});

partialBundling.enforceResources

  • default: []

Array to match the modules that should always be in the same output resource, ignore all other constraints.

Options for each item:

  • name: Name of this resource.
  • test: Regex array to match the modules which are in this resource.
farm.config.ts
export default defineConfig({
  compilation: {
    partialBundling: {
      enforceResources: [
        {
          name: "index",
          test: [".+"],
        },
      ],
    },
  },
});

partialBundling.enforceTargetConcurrentRequests

  • default: false

Enforce target concurrent requests for every resource loading, when true, smaller resource will be merged into bigger resource to meet the target concurrent requests. this may cause issue for css resource, be careful to use this option.

partialBundling.enforceTargetMinSize

  • default: false

Enforce target min size for every resource, when tue, smaller resource will be merged into bigger resource to meet the target concurrent requests. this may cause issue for css resource, be careful to use this option

partialBundling.immutableModules

  • default: ['node_modules']

Regex array to match the immutable modules.

farm.config.ts
export default defineConfig({
  compilation: {
    partialBundling: {
      immutableModules: ["node_modules/", "/global-constants"],
    },
  },
});

Immutable module can affect bundling and incoming persistent cache, be careful if you want to change it.

partialBundling.immutableModulesWeight

  • default: 0.8

Default to 0.8, means the output bundles of immutable module takes 80%. for example, if targetConcurrentRequest is 25,then immutable bundles files numbers are 25 * 80% = 20. This option is used isolate your mutable and immutable module, if you modified your business code, bundles generating from node_modules won't be affected.

lazyCompilation

  • default: true in development mode, false in build mode

Whether to enable lazy compilation, configure to false to close. See lazy compilation.

treeShaking

  • default: false in development mode, true in build mode

Whether to enable tree shake, set to false to close. See Tree Shake.

minify

  • default: false in development mode, true in build mode

Whether to enable compression, the product will be compressed and confused after it is turned on. See Minification.

ts
type MinifyOptions = boolean | {
  compress?: ToSnakeCaseProperties<TerserCompressOptions> | boolean;
  mangle?: ToSnakeCaseProperties<TerserMangleOptions> | boolean;
  include?: string[];
  exclude?: string[];
  mangleExports?: boolean;
};

The compress and mangle options is the same as swc's minify config.

minify.compress

compress option

minify.mangle

compress variable parameters

minify.include

  • default: []
  • type: string[]

Contains modules that need to be compressed. When empty, all matching modules are included.

minify.exclude

  • default: [".+\\.min\\.(js|css|html)$"]
  • type: string[]

Excludes modules that should not be compressed.

minify.mangleExports

  • default: true
  • type: boolean

Whether to mangle internal export names during minification.

presetEnv

  • default: false in development mode, true in build mode
ts
type FarmPresetEnvConfig =
  | boolean
  | {
      include?: string[];
      exclude?: string[];
      // TODO using swc's config
      options?: any;
      assumptions?: any;
    };

By default, polyfills will not be injected into modules under node_modules, if necessary, please use include to add polyfills.

presetEnv.include

  • default: []

Include additional modules that require polyfill, configure regular strings, for example include: ['node_modules/(es6-package|my-package)/']

presetEnv.exclude

  • default: ['node_modules/']

Configure modules that do not require polyfill, and configure regular strings, such as exclude: ['custom-path/(es5-package|my-package)/']. By default node_modules is excluded, if you need to include excluded modules, it is recommended to use include

presetEnv.options

  • default: downgrade to ES5

Options passed to swc preset env, see https://swc.rs/docs/configuration/compilation#env.

persistentCache

  • default: true

Options for Persistent Cache. Configuring it false to disable cache.

ts
export type PersistentCache =
  | boolean
  | {
      namespace?: string;
      cacheDir?: string;
      buildDependencies?: string[];
      moduleCacheKeyStrategy?: {
        timestamp?: boolean;
        hash?: boolean;
      };
      envs?: Record<string, string>;
      globalBuiltinCacheKeyStrategy?: {
        define?: boolean;
        buildDependencies?: boolean;
        lockfile?: boolean;
        packageJson?: boolean;
        env?: boolean;
      };
    };

persistentCache.namespace

  • default: farm-cache

Namespace for the cache, caches under different namespace will be isolated.

persistentCache.cacheDir

  • default: node_modules/.farm/cache

Cache store directory.

persistentCache.buildDependencies

  • default: farm.config.ts and all its deep dependencies

File path or package name that may affect the compilation, for example, plugins. By default, farm.config.ts/js/mjs and all of its deep dependencies will be treated as build dependencies, if any of these files changed, all cache will be invalidated.

it can be a file path or a package name, for example:

ts
import { defineConfig } from "@farmfe/core";
import path from "node:path";

export default defineConfig({
  compilation: {
    persistentCache: {
      buildDependencies: [
        // a file path
        path.resolve(process.cwd(), "./plugins/my-plugin.js"),
        // a package name, note that this package must expose package.json
        "farm-plugin-custom-xxx",
      ],
    },
  },
});

persistentCache.moduleCacheKeyStrategy

  • default: { timestamp: true, hash: true }

How to generate cache key when trying to reuse cache. if timestamp is true and the timestamp of the module is not changed, then all build stage hooks like load, transform will be skipped and the cached module will be reused. if hash is true and the content of the module is not changed, load and transform hook will be called to get the transformed content, other hooks will be skipped and the cached module will be reused.

  • timestamp: whether check timestamp of the module, which has the best performance
  • hash: whether check content hash after load and transform

persistentCache.envs

Envs used to invalidate cache, if the configured env changed, then all cache will be invalidated.

persistentCache.globalBuiltinCacheKeyStrategy

  • default: { define: true, buildDependencies: true, lockfile: true, packageJson: true, env: true }

Controls whether Farm's built-in cache keys are included when computing the global cache key. If any of these built-in keys change, the entire cache is fully invalidated. You can selectively disable keys that you know won't affect your build:

  • define: Whether changes to compilation.define invalidate cache.

  • buildDependencies: Whether changes to buildDependencies invalidate cache.

  • lockfile: Whether changes to the lockfile (e.g. pnpm-lock.yaml) invalidate cache.

  • packageJson: Whether changes to package.json invalidate cache.

  • env: Whether changes to environment variables invalidate cache.

progress

  • default: true

Enable progress bar or not.

comments

  • default: license

Preserve comments or not:

  • true: Preserve all comments
  • false: Remove all comments
  • license: Preserve all LICENSE comments, and remove the others

concatenateModules

  • default: false

Whether to enable module concatenation (scope hoisting). When enabled, Farm will merge modules into a single scope where possible, similar to webpack's ModuleConcatenationPlugin. This can reduce bundle size and improve runtime performance by eliminating module wrapper overhead.

record

  • default: false

Whether to record compilation flow statistics. When enabled, Farm collects internal data about the compilation process, useful for debugging and performance analysis.

custom

  • default: {}
  • type: Record<string, any>

Reserved configuration field for passing custom key-value pairs. Can be used to pass arbitrary data to plugins or for future compatibility.

100%

Drag or pinch to explore. Keyboard: + / − zoom, arrows pan, 0 resets, Esc closes.