> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# lib.externalHelpers

- **Type:** `boolean`
- **Default:** `false`
- **Top-level config:** Supported

Whether to import SWC helper functions from [@swc/helpers](https://www.npmjs.com/package/@swc/helpers) instead of inlining them.

By default, the output JavaScript file may depend on helper functions to support the target environment or output format, and these helper functions will be inlined in the file that requires it.

When `externalHelpers` set to `true`, the output JavaScript will import helper functions from the external module `@swc/helpers`. This helps reduce duplicate helper code in the final bundles, and reduces the bundle size.

::: note

Make sure to declare and install `@swc/helpers` in `dependencies` field of `package.json`.

:::

## Example

Take the following code as an example:

```ts title="index.ts"
export default class FOO {
  get bar() {
    return;
  }
}
```

When `externalHelpers` is disabled, the output JavaScript will inline helper functions.

```ts title="rslib.config.ts"
export default {
  lib: [
    {
      syntax: 'es5',
      externalHelpers: false, // [!code highlight]
    },
  ],
};
```

Below is the output JavaScript file, the highlighted code is the inlined helper functions:

```js title="index.js"
// [!code highlight:18]
function _class_call_check(instance, Constructor) {
  if (!(instance instanceof Constructor))
    throw new TypeError('Cannot call a class as a function');
}
function _defineProperties(target, props) {
  for (var i = 0; i < props.length; i++) {
    var descriptor = props[i];
    descriptor.enumerable = descriptor.enumerable || false;
    descriptor.configurable = true;
    if ('value' in descriptor) descriptor.writable = true;
    Object.defineProperty(target, descriptor.key, descriptor);
  }
}
function _create_class(Constructor, protoProps, staticProps) {
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  if (staticProps) _defineProperties(Constructor, staticProps);
  return Constructor;
}
var src_FOO = /*#__PURE__*/ (function () {
  'use strict';
  function FOO() {
    _class_call_check(this, FOO);
  }
  _create_class(FOO, [
    {
      key: 'bar',
      get: function () {},
    },
  ]);
  return FOO;
})();
export { src_FOO as default };
```

When `externalHelpers` is enabled, the output JavaScript will import helper functions from the external module `@swc/helpers`.

```ts title="rslib.config.ts"
export default {
  lib: [
    {
      syntax: 'es5',
      externalHelpers: true, // [!code highlight]
    },
  ],
};
```

Below is the output JavaScript file, the highlighted code is importing helper functions:

```js title="index.js"
// [!code highlight:2]
import { _ } from '@swc/helpers/_/_class_call_check';
import { _ as _create_class_ } from '@swc/helpers/_/_create_class';
var src_FOO = /*#__PURE__*/ (function () {
  'use strict';
  function FOO() {
    _(this, FOO);
  }
  _create_class_(FOO, [
    {
      key: 'bar',
      get: function () {},
    },
  ]);
  return FOO;
})();
export { src_FOO as default };
```
