自定义ui组件库 发布npm 安装

自定义组件

index.js

// 导入组件文件
import WxxButton from './components/WxxButton.vue';
import WxxSwiper from './components/WxxSwiper.vue';

// 放置到数组当中
const components = [WxxButton,WxxSwiper]

export default {
	install: (app, options) => {
		components.forEach(item => {
			// 循环导入组件
			app.component(item.name, item);
		})
	}
};

WxxButton.vue

<template>
	<button>自定义按钮</button>
</template>

<script>
/**
 * @Description: file content
 * @Autor: wxx
 * @Date: ${DATE}
 */
export default {
	name: 'WxxButton'
}
</script>

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

WxxSwiper.vue

<template>
	<div>自定义轮播组件</div>
</template>

<script>
/**
 * @Description: file content
 * @Autor: wxx
 * @Date: ${DATE}
 */
export default {
	name: 'WxxSwiper'
}
</script>

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

package.json

{
  "name": "npmuimyself",
  "version": "0.0.3",
  "description": "ui库描述",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "前端",
    "ui框架"
  ],
  "author": "wxx",
  "license": "ISC"
}

npm 发版步骤

  1. 在项目跟目录下通过 npm init 或 yarn init 生成package.json文件

  2. 在官网注册npm账号:https://www.npmjs.com/

  3. 登录到官网进行邮箱验证

    • npm 国外服务器 可能需要翻墙
  4. npm login

  5. npm publish

  • 推送 npm publish --access public 以公共的发布,谁都可以下载,私有的话需要费用,名称前面加@符号
需要注意项:版本号相同、名称前 @符号 代表是私有的、包名不能有斜杠等特殊字符
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值