14.2.企业级脚手架-tsup的配置和使用

1.配置tsup

  • 执行pnpm i tsup,npm install -g typescript
  • tsc --init分别在根目录和cli目录下执行

根节点创建tsconfig.json文件

子项目的tsconfig.json文件继承根节点的tsconfig.json文件

1. tsup.config.ts配置

ts 复制代码
import { defineConfig } from "tsup"

export default  defineConfig ({
    "dts": true,
    "entry": ["./index.ts"],
    "format": ["cjs"],
    "outDir": "dist"

})

2.企业级脚手架\wzm-cli\tsconfig.json

json 复制代码
{
    "compilerOptions": {
        "target": "ES2015",
        "lib": ["ESNext", "DOM"],
        "module": "ESNext",
        "moduleResolution": "node",
    },
    "include": ["packages/**/*"]
}

3.企业级脚手架\wzm-cli\packages\cli\tsconfig.json

json 复制代码
{
    "extends": "../../tsconfig.json",
    "exclude": ["node_modules","dist"],
    "include": ["src","./tsup.config.ts"]
}

生成index.d.ts文件

4.根节点tsconfig.json配置,或者子节点配置

json 复制代码
{
    "extends": "../../tsconfig.json",
    "compilerOptions": {
        "declaration": true
    },

    "exclude": ["node_modules","dist"],
    "include": ["src","tsup.config.ts"]
}

tsconfig.json配置

javascript 复制代码
import { defineConfig } from "tsup"

export default  defineConfig ({
    "dts": true, // 生成类型声明文件
    "entry": ["./index.ts"], // 入口文件
    "format": ["cjs"], // 打包格式 cjs esm umd iife commonjs amd system
    "outDir": "dist" // 输出目录 
})

5.cli下的pacckage.json文件

json 复制代码
  "scripts": {
    "dev": "tsup --watch",
    "build": "tsup"
},

6.修改bin/wzmtest文件

javascript 复制代码
require('../dist/index.js')
console.log('hello world')

重新执行npm linkpnpm run build 及 "wzm-cli-demo"

相关推荐
恋猫de小郭几秒前
AGP 9.2 开始,Android 上协程启动和取消速度提升两倍
android·前端·flutter
Ulyanov2 分钟前
Python与YAML的优雅交响:从配置管理到数据艺术的完美实践 (一)
开发语言·前端·python·数据可视化
SuperEugene7 分钟前
Python 函数与模块化:前端工程化思维完全通用| 基础篇
前端·python·状态模式
萧行之1 小时前
Ubuntu Node.js 版本管理工具 n 完整安装与使用教程
linux·前端
devlei8 小时前
从源码泄露看AI Agent未来:深度对比Claude Code原生实现与OpenClaw开源方案
android·前端·后端
Jagger_9 小时前
周末和AI肝了两天,终于知道:为什么要把AI当做实习生
前端
weixin_456164839 小时前
vue3 子组件向父组件传参
前端·vue.js
沉鱼.449 小时前
第十二届题目
java·前端·算法
Setsuna_F_Seiei9 小时前
CocosCreator 游戏开发 - 多维度状态机架构设计与实现
前端·cocos creator·游戏开发
Bigger9 小时前
CodeWalkers:让 AI 助手化身桌面宠物,陪你敲代码的赛博伙伴!
前端·app·ai编程