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"

相关推荐
gnip7 分钟前
pnpm 的 monorepo架构多包管理
前端·javascript
新手村领路人1 小时前
Firefox自定义备忘
前端·firefox
乖女子@@@2 小时前
css3新增-网格Grid布局
前端·css·css3
伐尘2 小时前
【CE】图形化CE游戏教程通关手册
前端·chrome·游戏·逆向
不想吃饭e2 小时前
在uniapp/vue项目中全局挂载component
前端·vue.js·uni-app
非凡ghost3 小时前
AOMEI Partition Assistant磁盘分区工具:磁盘管理的得力助手
linux·运维·前端·数据库·学习·生活·软件需求
UrbanJazzerati3 小时前
前端入门:margin居中、border、box-radius、transform、box-shadow、mouse事件、preventDefault()
前端·面试
蝎子莱莱爱打怪3 小时前
🚀🚀🚀嗨,一起来开发 开源IM系统呀!
前端·后端·github
Enddme3 小时前
《前端笔试必备:JavaScript ACM输入输出模板》
前端·javascript·面试
前端鱼3 小时前
前端面试中值得关注的js题
前端·面试