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

# tsup

This section introduces how to migrate a project using tsup to Rslib.

## Using Agent Skills

If you are using a Coding Agent that supports Skills, install the [migrate-to-rslib](https://github.com/rstackjs/agent-skills#migrate-to-rslib) skill to help with the migration process.


```sh [npx]
npx skills add rstackjs/agent-skills --skill migrate-to-rslib
```

```sh [yarn]
yarn dlx skills add rstackjs/agent-skills --skill migrate-to-rslib
```

```sh [pnpm]
pnpm dlx skills add rstackjs/agent-skills --skill migrate-to-rslib
```

```sh [bunx]
bunx skills add rstackjs/agent-skills --skill migrate-to-rslib
```

```sh [deno]
deno run -A npm:skills add rstackjs/agent-skills --skill migrate-to-rslib
```

After installation, let the Coding Agent guide you through the migration process.

## Installing dependencies

First, you need to replace the npm dependencies of tsup with Rslib's dependencies.

- Remove tsup:


```sh [npm]
npm remove tsup
```

```sh [yarn]
yarn remove tsup
```

```sh [pnpm]
pnpm remove tsup
```

```sh [bun]
bun remove tsup
```

```sh [deno]
deno remove npm:tsup
```

- Install Rslib:


```sh [npm]
npm add @rslib/core -D
```

```sh [yarn]
yarn add @rslib/core -D
```

```sh [pnpm]
pnpm add @rslib/core -D
```

```sh [bun]
bun add @rslib/core -D
```

```sh [deno]
deno add npm:@rslib/core -D
```

## Updating npm scripts

Next, you need to update the npm scripts in your `package.json` to use Rslib's CLI commands.

```diff title="package.json"
{
  "scripts": {
-   "build": "tsup",
-   "build:watch": "tsup --watch",
+   "build": "rslib",
+   "build:watch": "rslib --watch"
  }
}
```

## Create configuration file

Create a Rslib configuration file `rslib.config.ts` in the same directory as `package.json`, and add the following content:

```ts title="rslib.config.ts"
import { defineConfig } from '@rslib/core';

export default defineConfig({});
```

## Configuration migration

Here is the corresponding Rslib configuration for tsup configuration:

| tsup          | Rslib                                                                                                                               |
| ------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| banner        | [lib.banner](/config/lib/banner.md)                                                                                                 |
| bundle        | [lib.bundle](/config/lib/bundle.md)                                                                                                 |
| clean         | [output.cleanDistPath](/config/rsbuild/output.md#outputcleandistpath)                                                               |
| define        | [source.define](/config/rsbuild/source.md#sourcedefine)                                                                             |
| dts           | [lib.dts](/config/lib/dts.md)                                                                                                       |
| entry         | [source.entry](/config/rsbuild/source.md#sourceentry)                                                                               |
| external      | [output.externals](/config/rsbuild/output.md#outputexternals) / [output.autoExternal](/config/rsbuild/output.md#outputautoexternal) |
| format        | [lib.format](/config/lib/format.md)                                                                                                 |
| footer        | [lib.footer](/config/lib/footer.md)                                                                                                 |
| minify        | [output.minify](/config/rsbuild/output.md#outputminify)                                                                             |
| platform      | [output.target](/config/rsbuild/output.md#outputtarget)                                                                             |
| plugins       | [plugins](/config/rsbuild/plugins.md)                                                                                               |
| sourcemap     | [output.sourceMap](/config/rsbuild/output.md#outputsourcemap)                                                                       |
| shims         | [lib.shims](/config/lib/shims.md)                                                                                                   |
| terserOptions | [output.minify](/config/rsbuild/output.md#outputminify)                                                                             |
| tsconfig      | [source.tsconfigPath](/config/rsbuild/source.md#sourcetsconfigpath)                                                                 |

## Example

Here is an example of migrating a typical `tsup` configuration to Rslib:

```ts title="tsup.config.ts"
import { defineConfig } from 'tsup';

export default defineConfig({
  entry: ['./src/index.ts'],
  format: ['esm', 'cjs'],
  dts: true,
  clean: true,
});
```

The corresponding Rslib configuration is as follows:

```ts title="rslib.config.ts"
import { defineConfig } from '@rslib/core';

export default defineConfig({
  lib: [
    {
      format: 'esm',
      dts: true,
    },
    {
      format: 'cjs',
      dts: true,
    },
  ],
  source: {
    entry: {
      index: './src/index.ts',
    },
  },
  output: {
    cleanDistPath: true,
  },
});
```

## Validating results

After completing the above steps, you have finished the basic migration from tsup to Rslib. You can now run the `npm run build` command to build the outputs and verify that the directory structure and extensions of the outputs are consistent with those before the migration.

If you encounter issues during the build process, please debug according to the error logs. You can also enable [debug mode](/guide/basic/configure-rslib.md#debug-mode) to view the final configurations generated by Rslib, or check the `tsup.config.ts` configuration to see if any required configurations have not been migrated to Rslib.

## Contents supplement

The current document only covers part of the migration process. If you find suitable content to add, feel free to contribute to the documentation via a pull request 🤝.

> The documentation for Rslib can be found in the [rslib/website](https://github.com/web-infra-dev/rslib/tree/main/website) directory.
