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"

相关推荐
小码哥_常5 分钟前
安卓黑科技:实现多平台商品详情页一键跳转APP
前端
killerbasd9 分钟前
还是迷茫 5.3
前端·react.js·前端框架
不会敲代码11 小时前
TCP/IP 与前端性能:从数据包到首次渲染的底层逻辑
前端·tcp/ip
kyriewen1 小时前
奥特曼借GPT-5.5干杯,而你的Copilot正按Token收钱
前端·github·openai
AC赳赳老秦1 小时前
投标合规提效:用 OpenClaw 实现标书 / 合同自动审核、关键词校验、格式优化,降低废标风险
开发语言·前端·python·eclipse·emacs·deepseek·openclaw
kyriewen1 小时前
代码写成一锅粥?3个设计模式让你的项目“起死回生”
前端·javascript·设计模式
千寻girling2 小时前
《 Git 详细教程 》
前端·后端·面试
之歆3 小时前
DAY08_CSS浮动与行内块布局实战指南(下)
前端·css
yqcoder3 小时前
CSS Position 全解析:5 种定位模式详解
前端·css
Rhi6374 小时前
从零搭建项目:React 19 + Vite 8 + Tailwind CSS v4 实战配置
前端