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

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


🍣 一个Farm Rust插件，用于从你的代码中移除` debugger `语句和如` assert.equal `、` console.log `这样的函数。


<a id="要求"></a>
## 要求


这个插件需要一个[LTS](<https://github.com/nodejs/Release>) Node版本（v18.0.0+）和Farm v1.0.0+。


<a id="安装"></a>
## 安装


**npm**

```javascript
npm install @farmfe/plugin-strip
```


**yarn**

```javascript
yarn add @farmfe/plugin-strip
```


**pnpm**

```javascript
pnpm add @farmfe/plugin-strip
```



<a id="使用"></a>
## 使用


创建一个` farm.config.js `[配置文件](<https://www.farmfe.org/docs/config/configuring-farm>)并导入插件：


```js
import { defineConfig } from '@farmfe/core';
import strip from '@farmfe/plugin-strip';

export default defineConfig({
  // ...
  plugins: [
    [
      strip({
        // 插件选项
        functions:[ 'console.*', 'assert.*' ],
        labels: ['unittest']
      })
    ]
  ],
  // ...
});
```


<a id="选项"></a>
## 选项


<a id="include"></a>
### ` include `


类型: ` String | RegExp | Array[...String|RegExp] `  

默认值: ` ['**/*.js'] `  

示例: ` include: '**/*.(mjs|js)', `


指定插件应操作的构建中的文件的模式或模式数组。


<a id="exclude"></a>
### ` exclude `


类型: ` String | RegExp | Array[...String|RegExp] `  

默认值: ` [] `  

示例: ` exlude: 'tests/**/*', `


指定插件应\_忽略\_的构建中的文件的模式或模式数组。


<a id="debugger"></a>
### ` debugger `


类型: ` Boolean `  

默认值: ` true `  

示例: ` debugger: false, `


如果为` true `，指示插件移除debugger语句。


<a id="functions"></a>
### ` functions `


类型: ` Array[...String] `  

默认值: ` [ 'console.*', 'assert.*' ] `  

示例: ` functions: [ 'console.log', 'MyClass.Test' ], `


指定插件将目标定位和移除的函数。


*注意：指定在链的开头使用的函数，如'a().b().c()'，将导致'(void 0).b().c()'，这在运行时会产生错误。*


<a id="labels"></a>
### ` labels `


类型: ` Array[...String] `  

默认值: ` [] `  

示例: ` labels: ['unittest'], `


指定插件将目标定位和移除的[带标签的块或语句](<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label>)。


*注意：'**:**'是隐含的，不应在配置中指定。*


<a id="sourcemap"></a>
### ` sourceMap `


类型: ` Boolean `  

默认值: ` true `  

示例: ` sourceMap: false, `


如果为` true `，指示插件在从捆绑包中移除配置的目标后相应地更新源映射。
