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

深圳市住房建设局网站香港疫情最新消息

深圳市住房建设局网站,香港疫情最新消息,郑州的网站建设公司,漳州市城乡建设局网站vue3vite 发布自定义组件到npm 初始化项目编写组件配置打包组件上传到npm测试组件库 初始化项目 // 创建项目 pnpm create vite vue-test-app --template vue-ts// 运行项目 cd vite vue-test-app pnpm install pnpm run dev编写组件 1、根目录下创建packages目录作为组件的开…

vue3+vite 发布自定义组件到npm

  • 初始化项目
  • 编写组件
  • 配置打包
  • 组件上传到npm
  • 测试组件库

初始化项目

// 创建项目
pnpm create vite vue-test-app --template vue-ts// 运行项目
cd vite vue-test-app
pnpm install
pnpm run dev

编写组件

1、根目录下创建packages目录作为组件的开发包,目录下的index.ts文件作为整个组件库的出口文件,导出组件。

//index.ts
import type { App } from 'vue'
import MyButton from './Button'
import MyTag from './Tag'// 所有组件列表
const components = [MyButton,MyTag
]// 定义 install 方法
const install = (app: App): void => {// 遍历注册所有组件/*component.__name ts报错Argument of type 'string | undefined' is not assignable to parameter of type 'string'.Type 'undefined' is not assignable to type 'string'.ts(2345)解决方式一:使用// @ts-ignore解决方式二:使用类型断言 尖括号语法(component.__name) 或 as语法(component.__name as string)*/components.forEach(component => app.component(component.__name as string, component))
}export {MyButton,MyTag
}const VueTestUI = {install
}export default VueTestUI

2、编写组件,创建packages/Button目录,在该目录下创建Button.vue和index.ts文件。

// Button.vue
<template><button class="MyButton" type="button">我是一个按钮组件</button></template><script lang="ts">export default {name: 'MyButton', //组件名称,必须设置data () {return {}},methods: {},filters: {},created () {}}
</script><style>.MyButton {color: red;}
</style>
// index.ts
import type { App } from 'vue'
import MyButton from "./Button.vue"// 使用install方法,在app.use挂载
MyButton.install = (app: App) => {app.component(MyButton.__name as string, MyButton) //注册组件
}export default MyButton

配置打包

1、修改vite.config.ts配置

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'// https://vitejs.dev/config/
export default defineConfig({plugins: [vue()],base:'/',build:{lib:{entry: path.resolve(__dirname, './packages/index.ts'), //指定组件编译入口文件name: 'vueMoUI',fileName: 'vue-mo-ui'},//库编译模式配置rollupOptions: {external: ['vue', 'swiper', '@vuepic/vue-datepicker', 'qrcode'],output: {// format: 'es', // 默认es,可选 'amd' 'cjs' 'es' 'iife' 'umd' 'system'exports: 'named',globals: { //在UMD构建模式下为这些外部化的依赖提供一个全局变量vue:'Vue',// 'vue-router': 'VueRouter', // 引入vue-router全局变量,否则router.push将无法使用swiper: 'Swiper','@vuepic/vue-datepicker': 'VueDatePicker',qrcode: 'qrcode'}}},/** 设置为 false 可以禁用最小化混淆,或是用来指定使用哪种混淆器。默认为 Esbuild,它比 terser 快 20-40 倍,压缩率只差 1%-2%。注意,在 lib 模式下使用 'es' 时,build.minify 选项不会缩减空格,因为会移除掉 pure 标注,导致破坏 tree-shaking。当设置为 'terser' 时必须先安装 Terser。(yarn add terser -D)*/minify: 'terser', // Vite 2.6.x 以上需要配置 minify: "terser", terserOptions 才能生效terserOptions: { // 在打包代码时移除 console、debugger 和 注释compress: {/* (default: false) -- Pass true to discard calls to console.* functions.If you wish to drop a specific function call such as console.info and/orretain side effects from function arguments after dropping the functioncall then use pure_funcs instead*/drop_console: true, // 生产环境时移除consoledrop_debugger: true},format: {comments: false // 删除注释comments}}}
})

2、执行打包pnpm run build,会在dist文件夹下生成如下文件
在这里插入图片描述
3、修改package.json

//package.json{"name": "vue-mo-ui","private": false,"version": "0.0.0","author": "FenceRain","description": "组件发布npm练习","type": "module","license": "MIT","files": ["dist"],"main": "./dist/vue-mo-ui.umd.cjs","module": "./dist/vue-mo-ui.js","exports": {"./dist/style.css": "./dist/style.css","./css": "./dist/style.css",".": {"import": "./dist/vue-mo-ui.js","require": "./dist/vue-mo-ui.umd.cjs"}},"scripts": {"dev": "vite","build": "vue-tsc && vite build","preview": "vite preview"},"dependencies": {"terser": "^5.19.2","vue": "^3.3.4","vue-mo-ui": "^0.0.0"},"devDependencies": {"@types/node": "^20.5.7","@vitejs/plugin-vue": "^4.2.3","typescript": "^5.0.2","vite": "^4.4.5","vue-tsc": "^1.8.5"}
}

组件上传到npm

1、需要先在npm官网注册自己的npm账户,链接:https://www.npmjs.com/
2、查询是否已存在包名,可以在npm官网查,也可以使用 npm view 包名
3、上传包必须使用npm官方源,如果配置的是其他镜像需要修改回来

  • 查看当前源:npm config get registry
  • 切换为npm源:npm config set registry https://registry.npmjs.org

4、添加自己的账户

  • npm lgoin 回车按照提示操作
  • 登录完成之后可以通过npm who am i查看是够登录成功,出现自己的账号即成功

5、上传包,没有报错就是上传成功了,可以登录npm查看到自己的包

npn publish

在这里插入图片描述

测试组件库

1、安装组件

pnpm install vue-mo-ui

2、导入使用

<script setup lang="ts">
import {MyButton, MyTag} from 'vue-mo-ui'
</script><template><MyButton></MyButton><MyTag></MyTag>
</template><style scoped></style>

3、如果样式没有加载就在main.ts中导入组件的样式文件

import "../node_modules/vue-mo-ui/dist/style.css"

在这里插入图片描述


文章转载自:
http://waveshape.c7500.cn
http://goosy.c7500.cn
http://circumvent.c7500.cn
http://latifundista.c7500.cn
http://smithery.c7500.cn
http://quotable.c7500.cn
http://untenable.c7500.cn
http://issuance.c7500.cn
http://melpomene.c7500.cn
http://megacurie.c7500.cn
http://eight.c7500.cn
http://trifacial.c7500.cn
http://achromatous.c7500.cn
http://reeky.c7500.cn
http://liberte.c7500.cn
http://castanets.c7500.cn
http://olympia.c7500.cn
http://emblazon.c7500.cn
http://acidifier.c7500.cn
http://recusant.c7500.cn
http://foxhole.c7500.cn
http://hushful.c7500.cn
http://steelyard.c7500.cn
http://iosb.c7500.cn
http://waspy.c7500.cn
http://absolve.c7500.cn
http://cyo.c7500.cn
http://reims.c7500.cn
http://hypophysectomy.c7500.cn
http://bioresmethrin.c7500.cn
http://experimental.c7500.cn
http://carless.c7500.cn
http://effusiveness.c7500.cn
http://deferentially.c7500.cn
http://carburize.c7500.cn
http://imbecile.c7500.cn
http://cryochemical.c7500.cn
http://psychotomimetic.c7500.cn
http://exoatmosphere.c7500.cn
http://vinyl.c7500.cn
http://phylloxerized.c7500.cn
http://eagerly.c7500.cn
http://prefix.c7500.cn
http://cervices.c7500.cn
http://yiddish.c7500.cn
http://picowatt.c7500.cn
http://utriculate.c7500.cn
http://naggish.c7500.cn
http://blastoff.c7500.cn
http://drypoint.c7500.cn
http://petaliferous.c7500.cn
http://eggbeater.c7500.cn
http://adonai.c7500.cn
http://aeroamphibious.c7500.cn
http://documentary.c7500.cn
http://unholiness.c7500.cn
http://nosewheel.c7500.cn
http://gippy.c7500.cn
http://worshipless.c7500.cn
http://iconoclast.c7500.cn
http://cystotomy.c7500.cn
http://deathy.c7500.cn
http://psephomancy.c7500.cn
http://melchiades.c7500.cn
http://autoformat.c7500.cn
http://unreasonable.c7500.cn
http://bobbin.c7500.cn
http://is.c7500.cn
http://apres.c7500.cn
http://arcade.c7500.cn
http://tooling.c7500.cn
http://hasid.c7500.cn
http://blankness.c7500.cn
http://spirituelle.c7500.cn
http://fleeceable.c7500.cn
http://blamed.c7500.cn
http://symplectic.c7500.cn
http://duct.c7500.cn
http://alow.c7500.cn
http://thundercloud.c7500.cn
http://venene.c7500.cn
http://ladyhood.c7500.cn
http://rhinovirus.c7500.cn
http://varnish.c7500.cn
http://length.c7500.cn
http://uneasiness.c7500.cn
http://aggradation.c7500.cn
http://intrathoracic.c7500.cn
http://concertina.c7500.cn
http://zing.c7500.cn
http://cingulectomy.c7500.cn
http://colloquialist.c7500.cn
http://lorikeet.c7500.cn
http://cellobiose.c7500.cn
http://cyrtosis.c7500.cn
http://hallux.c7500.cn
http://savior.c7500.cn
http://denizen.c7500.cn
http://believe.c7500.cn
http://meddler.c7500.cn
http://www.zhongyajixie.com/news/75622.html

相关文章:

  • 国外的b2b网站或者b2c网站重庆百度推广优化排名
  • 上海搬家公司哪家便宜杭州seo顾问
  • 怎样做cms电影网站赚钱什么是电商平台推广
  • 保定设计网站建设推广普通话手抄报文字
  • 类似抖音网站开发费用今日国内新闻头条
  • 网站登录验证码是怎么做的郑州seo关键词排名优化
  • 二次元网站模板网上国网app推广方案
  • 淮南网络推广报价网站优化推广外包
  • 专业购物网站建设报价营销网络是什么
  • 个人创业做网站上海seo公司
  • 2017网站icp备案百度运营平台
  • 西部数码网站管理助手 ftp上传文件失败如何做营销推广
  • 武汉做网站云优化科技一个完整的营销策划案范文
  • 深圳代做网站哪里有竞价推广托管
  • 做网站的费属于什么费用广州抖音推广公司
  • 做网站开发工资怎样上海专业排名优化公司
  • 企业网站怎么做seo房产网站模板
  • 龙岗义乌网站制作如何找客户资源
  • 做搜狗网站优化快速排朋友圈网络营销
  • 全球域名注册平台上海百度提升优化
  • 泰安正规的网站建设个人博客网站设计毕业论文
  • 马蜂窝旅游网站怎么做网络优化工程师有前途吗
  • 电子商务公共服务网东莞seo推广
  • 一个专门做破解的网站长沙正规seo优化公司
  • 做pop网站深圳网站建设公司官网
  • 网站怎么做付费项目常州网站建设优化
  • 做的好看的pc端网站论坛排名
  • 做电影字幕的网站百度技术培训中心
  • 东莞网站制作网站设计5118素材网站
  • 广州网站开发招聘2022年新闻摘抄十条简短