首页 > 其他分享 >从0搭建vue3组件库:自动化发布、管理版本号、生成 changelog、tag

从0搭建vue3组件库:自动化发布、管理版本号、生成 changelog、tag

时间:2022-10-26 09:57:51浏览次数:57  
标签:changelog 版本号 kitty 组件 ui vue3 release type

今天看到一篇文章中提到了一个好用的工具release-it。刚好可以用在我正在开发的vue3组件库。纸上得来终觉浅,绝知此事要躬行,说干就干,下面就介绍如何将release-it应用到实际项目中,让组件库可以自动化发布、管理版本号、生成 changelog、tag等

项目调整

在使用这个工具之前先对组件库进行进行一些调整,这里仅是对项目本身的优化和release-it无关。

  • 首先修改vite.config.ts将打包后的目录dist更改为kitty-ui
  • 自动打包中的删除打包文件改成nodejs方式实现(script/utils/delpath.ts)。打包之前先将kitty-ui文件下的目录全部删除只留下package.json,这个package.json就是正式发布组件库所用的配置
import fs from 'fs'
const delDir = async (path: string) => {
    let files: string[] = [];
    if (fs.existsSync(path)) {
        files = fs.readdirSync(path);
        files.forEach(async (file) => {
            let curPath = path + "/" + file;
            if (fs.statSync(curPath).isDirectory()) { 
                await delDir(curPath);
            } else { // 保留package.json文件
                if (file != 'package.json') {
                    fs.unlinkSync(curPath);
                }
            }

        });

        if (path != `${componentPath}/kitty-ui`) fs.rmdirSync(path);
    }

};
export default delDir

使用release-it

安装

pnpm add release-it -D -w

配置

在打包后文件kitty-ui下的package.json中加入script脚本以及git仓库

{
  "name": "kitty-ui",
  "version": "4.2.0",
  "main": "lib/index.js",
  "module": "es/index.mjs",
  "files": [
    "es",
    "lib"
  ],
  "scripts": {
    "release": "release-it"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/geeksdidi/kittyui"
  },
  "keywords": [
    "kitty-ui",
    "vue3组件库"
  ],
  "dependencies": {
    "@kitty-ui/utils": "2.0.3"
  },
  "sideEffects": [
    "**/*.css"
  ],
  "author": "小月",
  "license": "MIT",
  "description": "",
  "typings": "lib/index.d.ts"
}

修改根目录package.jsonscript中的publish:kitty,让其进入打包后文件夹kitty-ui执行release命令.

image.png

在发布之前需要先将我们的改动提交到git上,然后在根目录执行

pnpm run publish:kitty

image.png

image.png

这里会让我们选择发布版本号、是否发布、是否创建tag等等

生成changelog

  • 安装@release-it/conventional-changelog
pnpm add @release-it/conventional-changelog -D -w
  • 根目录新建.release-it.json
{
  "plugins": {
    "@release-it/conventional-changelog": {
      "preset": {
        "name": "conventionalcommits",
        "types": [
          { "type": "feat", "section": "Features" },
          { "type": "fix", "section": "Bug Fixes" },
          { "type": "chore", "hidden": true },
          { "type": "docs", "hidden": true },
          { "type": "style", "hidden": true },
          { "type": "refactor", "hidden": true },
          { "type": "perf", "hidden": true },
          { "type": "test", "hidden": true }
        ]
      },
      "infile": "../../../CHANGELOG.md"
    }
  }
}

然后执行pnpm run publish:kitty,就会发现根目录下生成CHANGELOG.md文件

## [4.2.0](https://github.com/geeksdidi/kittyui/compare/v4.1.1...v4.2.0) (2022-10-21)


### Features

* test ([b69303c](https://github.com/geeksdidi/kittyui/commit/b69303c1c542bd51cd66330b89dd2bb774b09f73))

presettype配置表示只有featfix才会被记录,如提交的commit为fix: 改了一个bug

image.png

组件库

如果你对组件库开发感兴趣的话,欢迎关注公众号:web前端进阶,组件库所有实现包括环境搭建自动打包发布文档搭建vitest单元测试等等都在这里

标签:changelog,版本号,kitty,组件,ui,vue3,release,type
From: https://www.cnblogs.com/zdsdididi/p/16827229.html

相关文章

  • vue3模板编译
    @keyup.entervue<[email protected]>HelloWorld</div>jsimport{withKeysas_withKeys,openBlockas_openBlock,createElementBlockas_createElementBlock......
  • vue3+vite+ts 项目配置 @/路径
    vite.config.ts文件中前置条件下载types/node下面引入的path会用到npminstall@types/node--save-dev原因:path模块是node.js内置的功能,但是node.js本身并不支持ts,......
  • 网友心得—运行jeecgboot-vue3项目可能出现的问题
    运行jeecgboot-vue3项目可能出现的问题1.执行pnpminstall的时候报错ERR_PNPM_INVALID_OVERRIDE_SELECTOR Cannotparsethe"//"selectorintheoverrides​ 翻......
  • vue3 + ts 中出现 类型“typeof import(".........../node_modules/vue/dist/vue")”
    错误示例截图解决方法修改shims-vue.d.ts中的内容declaremodule"*.vue"{ import{defineComponent}from"vue"; constComponent:ReturnType<typeofdefineC......
  • vue3 更改编译端口号
    在package.json文件中修改scripts"scripts":{"serve":"vue-cli-serviceserve--port80","build":"vue-cli-servicebuild","lint":"vue-cli-s......
  • Vue3知识点之数据侦测
    Vue的核心之一就是响应式系统,通过侦测数据的变化,来驱动更新视图。实现可响应对象的方式通过可响应对象,实现对数据的侦测,从而告知外界数据变化。实现可响应对象的方式:g......
  • Vue3必会技巧-自定义Hooks
    Vue3自定义Hooks定义:个人理解:一些可复用的方法像钩子一样挂着,可以随时被引入和调用以实现高内聚低耦合的目标,应该都能算是hook;为什么Vue3要用自定义Hook?:结论:就是为了......
  • vue3 router 配置
     npminstallvue-router......
  • 从0搭建vue3组件库: 如何完整搭建一个前端脚手架?
    相信大家在前端开发中都使用过很多前端脚手架,如vue-cli,create-vite,create-vue等;本篇文章将会为大家详细介绍这些前端脚手架是如何实现的,并且从零实现一个create-kitty脚手......
  • vite+vue3使用tailwindcss
    vite+vue3使用1.通过npm安装Tailwindnpminstall-Dtailwindcss@latestpostcss@latestautoprefixer@latest2.创建您的配置文件npxtailwindcssinit这将会在......