---
title: "@farmfe/plugin-replace-dirname"
locale: "zh"
version: "current"
canonicalUrl: "https://farmfe.org/zh/docs/plugins/official-plugins/replace-dirname"
publicationStatus: "prerelease"
---

<a id="farmfeplugin-replace-dirname"></a>
# @farmfe/plugin-replace-dirname


Rust plugin that replaces Node-style path globals in script modules.


It rewrites ` __dirname `, ` __filename `, and ` import.meta.url ` to string literals based on the module path.


<a id="installation"></a>
## Installation


**npm**

```javascript
npm install @farmfe/plugin-replace-dirname
```


**yarn**

```javascript
yarn add @farmfe/plugin-replace-dirname
```


**pnpm**

```javascript
pnpm add @farmfe/plugin-replace-dirname
```



<a id="usage"></a>
## Usage


` @farmfe/core ` uses this plugin internally when bundling Farm config files. To register it manually, import the platform plugin path and pass it as a Rust plugin tuple:


```ts
import { defineConfig } from "@farmfe/core";
import replaceDirname from "@farmfe/plugin-replace-dirname";

export default defineConfig({
  plugins: [
    [replaceDirname, {
      include: ["src/"],
      exclude: ["node_modules/"],
    }],
  ],
});
```


<a id="options"></a>
## Options


- ` include?: string[] ` — regular expression strings for module paths to transform. Defaults to ` [] `.
- ` exclude?: string[] ` — regular expression strings for module paths to skip. Defaults to ` ["node_modules/"] `.



> [!WARNING]
> 注意
> 
> Unlike most Rust plugin packages, this package's default export is the resolved native plugin path string, not an options wrapper function.
