当前位置: 首页 > article >正文

vue3新建组件库项目并上传到私库

创建vue3项目,步骤省略

# nexus配置

访问 http://192.168.0.9:8081/
账号密码 admin Yanfabu01!
参考网址 https://www.jb51.net/javascript/3178205jj.htm

# 项目满足的条件
[tsconfig.json]中
添加"baseUrl": "."


[package.json]中
添加
"private": false,
"main": "/packages/index.js"


新建packages文件夹,编写组件

index.js代码

import { version } from '../package.json'

import TyInput from './input/tyInput.vue'
import TyButton from "./button/tyButton.vue";

const components = [TyInput, TyButton]

const install = function(Vue, opts = {}) {
  components.forEach(component => {
    Vue.component(component.name, component)
  })
}

/* istanbul ignore if */
if (typeof window !== 'undefined' && window.Vue) {
  install(window.Vue)
}

export default {
  version,
  ...components,
  install
}

 package.json中代码

{
  "name": "tuyang-ui-plus",
  "version": "1.0.0"
}

 建立组件tyButton,新建button文件夹,下面建立tyButton.vue和index.js

tyButton.vue代码

<template>
  <div>
    <el-button type="primary">Primary</el-button>
  </div>
</template>
<script setup>
// 组件命名
defineOptions({name: 'TyButton'})
</script>

<style lang="scss" scoped></style>

index.js中代码

// 导入组件
import TyButton from 'tyButton'

TyButton.install = function(Vue) {
  Vue.component('TyButton', TyButton)
}

export default TyButton

 项目中测试组件是否好用,src文件下新建index.vue

<template>
	<ty-button></ty-button>
</template>

<script setup lang="ts">
  import {ref} from "vue";
</script>

<style lang="scss" scoped>
</style>

# 组件库发布命令

## 设置本地仓库镜像源
npm config set registry http://192.168.0.9:8081/repository/tuyang-npm-group/

## 登录本地仓库
npm login --registry=http://192.168.0.9:8081/repository/tuyang-npm/
username:admin
password:Yanfabu01!
email:xxxxx

## 发布到本地仓库
npm publish --registry=http://192.168.0.9:8081/repository/tuyang-npm/

## 查看组件
浏览器访问 http://192.168.0.9:8081/


# 组件安装及使用

1. npm install tuyang-ui-plus

2.main.js中引入

        import tuYangUiPlus from 'tuyang-ui-plus'
        app.use(tuYangUiPlus)


http://www.kler.cn/a/533502.html

相关文章:

  • C/C++编译器
  • xxl-job 自定义告警短信发送
  • 为AI聊天工具添加一个知识系统 之87 详细设计之28 Derivation 统一建模元模型 之1
  • 7 与mint库对象互转宏(macros.rs)
  • 人工智能第2章-知识点与学习笔记
  • 线性调整器——耗能型调整器
  • 实时波形与频谱分析———傅立叶变换
  • RabbitMQ深度探索:消息幂等性问题
  • MongoDB 查询文档
  • 哈夫曼树原理及其C语言实现
  • 时间对象管理相关
  • gesp(C++六级)(13)洛谷:P11375:[GESP202412 六级] 树上游走
  • 因果推断与机器学习—可解释性、公平性和因果机器学习
  • go运算符
  • Redis缓存穿透、击穿、雪崩介绍以及解决方案
  • vscode 设置在编辑器的标签页超出可视范围时自动换行(workbench.editor.wrapTabs)
  • SpringBoot 基于个性化定制的智慧校园管理系统设计与开发 - 论文、开题报告
  • 搭建Python环境:为量化交易做准备
  • Linux之安装MySQL
  • Oh3.2项目升级到Oh5.0(鸿蒙Next)具体踩坑记录二
  • 正则表达式详细介绍
  • 题解:洛谷 P1744 采购特价商品
  • 算法随笔_39: 最多能完成排序的块_方法2
  • embeddingbag词袋
  • 协议的种类
  • RNN/LSTM/GRU 学习笔记