close
logo
Rslib
指南
配置
博客
English
简体中文
指南
配置
博客
English
简体中文
logo
Rslib

开始

介绍
快速上手
名词解释
NPM 包

解决方案

Node.js
React
Vue

基础

命令行工具
配置 Rslib
使用 TypeScript
产物输出格式
产物结构
升级 Rslib

进阶

处理三方依赖
产物兼容性
类型生成
引用静态资源
引用 SVGR
引用 JSON 文件
模块联邦
使用 Storybook

迁移

Modern.js Module
tsup

常见问题

功能类问题
📝 在 GitHub 上编辑此页
上一页Modern.js Module
下一页功能类问题

#tsup

本章节介绍如何将使用 tsup 的项目迁移到 Rslib。

#安装依赖

首先,你需要将 tsup 的 npm 依赖替换为 Rslib 的依赖。

  • 移除 tsup:
npm
yarn
pnpm
bun
npm remove tsup
  • 安装 Rslib:
npm
yarn
pnpm
bun
npm add @rslib/core -D

#更新 npm 脚本

接下来,你需要更新 package.json 中的 npm 脚本,以使用 Rslib 的 CLI 命令。

package.json
{
  "scripts": {
-   "build": "tsup",
-   "build:watch": "tsup --watch",
+   "build": "rslib build",
+   "build:watch": "rslib build --watch"
  }
}

#创建配置文件

在 package.json 所在的同一目录中创建一个 Rslib 配置文件 rslib.config.ts,并添加以下内容:

rslib.config.ts
import { defineConfig } from '@rslib/core';

export default defineConfig({});

#配置迁移

以下是 tsup 配置对应的 Rslib 配置:

tsupRslib
bannerlib.banner
bundlelib.bundle
cleanoutput.cleanDistPath
definesource.define
dtslib.dts
entrysource.entry
externaloutput.externals / lib.autoExternal
formatlib.format
footerlib.footer
minifyoutput.minify
platformoutput.target
pluginsplugins
sourcemapoutput.sourceMap
shimslib.shims
terserOptionsoutput.minify
tsconfigsource.tsconfigPath

#内容补充

当前文档仅包含部分迁移过程。如果你发现合适的内容需要添加,请随时通过 pull request 贡献文档 🤝。

Rslib 的文档可以在 rslib/website 目录中找到。