尝试发布一个按钮npm包

昨天尝试了第一次发布一个npm包~还是比较简单的

又想起自己在之前整了一个hy-button组件,那么我能不能将这个组件运用起来发布到npm呢?以后自己也可以使用!

看看之前的组件

Vue3标签组件绘制--自定义按钮组件-CSDN博客

于是我找到了之前的组件,修改了下准备发布的npm包的文件结构,并将组件导出

重新发布了hy-button2.0.1版本

一.新建一个vue项目

javascript 复制代码
<template>
  <div class="blackbg"></div>
</template>
<style scoped>
.blackbg{
  background-color: black;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 500px;
  height: 500px;
}
</style>

清空主界面存放黑色背景板备用

二.下载less和hy-button组件

npm install less

npm install hy-button

三.配置全局

javascript 复制代码
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import { HyButton } from 'hy-button';

const app = createApp(App)

app.use(router)
app.component('HyButton', HyButton);
app.mount('#app')

四.使用

javascript 复制代码
<template>
  <div class="blackbg">
    <hy-button type='special'>坏越的按钮</hy-button>
  </div>
</template>
<style scoped>
.blackbg{
  background-color: black;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 500px;
  height: 500px;
}
</style>

javascript 复制代码
<template>
  <div class="blackbg">
    <hy-button plain round type="danger">坏越的按钮</hy-button>
    <hy-button plain block type="warn">坏越的按钮</hy-button>
    <hy-button plain block type="primary">坏越的按钮</hy-button>
  </div>
</template>
<style scoped>
.blackbg{
  background-color: black;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 500px;
  height: 500px;
}
</style>

上边是当前设定的一些方法,没有设定太多,可能还比较粗糙哈哈,有好的想法欢迎探讨~

相关推荐
如果你好几秒前
🔥 手撕call/apply/bind:从ES6用法到手写实现,吃透this指向核心
前端·javascript
大佬桑2 分钟前
Talend API Tester 接口测试插件 Google Chrome 浏览器的轻量级 API 测试插件
前端·chrome
阿西谈科技3 分钟前
利用 AI 写前端:从辅助编码到智能化开发的完整实践指南
前端
爱喝麻油的小哆3 分钟前
前端html导出pdf,(不完美)解决文字被切割的BUG,记录一下
前端
@大迁世界4 分钟前
React 以惨痛的方式重新吸取了 25 年前 RCE 的一个教训
前端·javascript·react.js·前端框架·ecmascript
晴殇i13 分钟前
【拿来就用】Uniapp路由守卫终极方案:1个文件搞定全站权限控制,老板看了都点赞!
前端·javascript·面试
嘿siri14 分钟前
uniapp enter回车键不触发消息发送,已解决
前端·前端框架·uni-app·vue
CodeCraft Studio15 分钟前
Excel处理控件Aspose.Cells教程:使用C#在Excel中创建树状图
前端·c#·excel·aspose·c# excel库·excel树状图·excel sdk
咬人喵喵28 分钟前
CSS Flexbox:拥有魔法的排版盒子
前端·css
LYFlied29 分钟前
TS-Loader 源码解析与自定义 Webpack Loader 开发指南
前端·webpack·node.js·编译·打包