Skip to content

Commit b821370

Browse files
chenjiahanfi3ework
andauthored
docs: tsup migration guide (#397)
Co-authored-by: Wei <[email protected]>
1 parent 95e1179 commit b821370

File tree

3 files changed

+95
-2
lines changed

3 files changed

+95
-2
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["modernjs-module"]
1+
["modernjs-module", "tsup"]
Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,87 @@
1-
# tsup
1+
# Tsup
2+
3+
This section introduces how to migrate a project using tsup to Rslib.
4+
5+
## Installing Dependencies
6+
7+
First, you need to replace the npm dependencies of tsup with Rslib's dependencies.
8+
9+
import { PackageManagerTabs } from '@theme';
10+
11+
- Remove tsup:
12+
13+
<PackageManagerTabs command="remove tsup" />
14+
15+
- Install Rslib:
16+
17+
<PackageManagerTabs command="add @rslib/core -D" />
18+
19+
## Updating npm scripts
20+
21+
Next, you need to update the npm scripts in your package.json to use Rslib's CLI commands.
22+
23+
```diff title="package.json"
24+
{
25+
"scripts": {
26+
- "build": "tsup",
27+
- "build:watch": "tsup --watch",
28+
+ "build": "rslib build",
29+
+ "build:watch": "rslib build --watch"
30+
}
31+
}
32+
```
33+
34+
## Create Configuration File
35+
36+
Create a Rslib configuration file `rslib.config.ts` in the same directory as package.json, and add the following content:
37+
38+
```ts title="rslib.config.ts"
39+
import { defineConfig } from '@rslib/core';
40+
41+
export default defineConfig({});
42+
```
43+
44+
## Configuration Migration
45+
46+
Here is the corresponding Rslib configuration for tsup configuration:
47+
48+
| tsup | Rslib |
49+
| ------------- | ------------------------------------------------------------------------------------------ |
50+
| banner | [lib.banner](/config/lib/banner) |
51+
| bundle | [lib.bundle](/config/lib/bundle) |
52+
| clean | [output.cleanDistPath](/config/rsbuild/output) |
53+
| define | [source.define](/config/rsbuild/source) |
54+
| dts | [lib.dts](/config/lib/dts) |
55+
| entry | [source.entry](/config/rsbuild/source) |
56+
| external | [output.externals](/config/rsbuild/output) / [lib.autoExternal](/config/lib/auto-external) |
57+
| format | [lib.format](/config/lib/format) |
58+
| footer | [lib.footer](/config/lib/footer) |
59+
| minify | [output.minify](/config/rsbuild/output) |
60+
| platform | [output.target](/config/rsbuild/output) |
61+
| plugins | [plugins](/config/rsbuild/plugins) |
62+
| sourcemap | [output.sourceMap](/config/rsbuild/output) |
63+
| shims | [lib.shims](/config/lib/shims) |
64+
| terserOptions | [output.minify](/config/rsbuild/output) |
65+
| tsconfig | [source.tsconfigPath](/config/rsbuild/source) |
66+
67+
## Platform
68+
69+
For `platform`, tsup defaults to `node` while Rslib defaults to `web` (the same as tsup's `browser`).
70+
71+
If your target platform is `node`, you can set `output.target` to `node`:
72+
73+
```ts title="rslib.config.ts"
74+
import { defineConfig } from '@rslib/core';
75+
76+
export default defineConfig({
77+
output: {
78+
target: 'node',
79+
},
80+
});
81+
```
82+
83+
## Contents Supplement
84+
85+
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 pull request 🤝.
86+
87+
> The documentation for Rslib can be found in the [rslib/website](https://github.com/web-infra-dev/rslib/tree/main/website) directory.

website/docs/en/guide/start/quick-start.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,10 @@ Options:
124124
--tools select additional tools (biome, eslint, prettier)
125125
--override override files in target directory
126126
```
127+
128+
## Migration
129+
130+
If you need to migrate from an existing project to Rslib, you can refer to the following guides:
131+
132+
- [Migrating from tsup](/guide/migration/tsup)
133+
- [Migrating from Modern.js Module](/guide/migration/modernjs-module)

0 commit comments

Comments
 (0)