vue插件开发

1.用脚手架创建个项目

vue create dom

2.新建个组件以及组件对应的index.js

 

 3.在入口文件中引入要打包成插件的文件

import vueDom from './HelloWorld.vue'
const install = (Vue) => {
    Vue.component('helloWorld', vueDom)
}
export default install
4.在main.js中引入试下
import Vue from 'vue'
import App from './App.vue'
import vuedom from './components/index'

Vue.config.productionTip = false
// Vue.component(vueDom, "HelloWorld")
Vue.use(vuedom)

new Vue({
  render: h => h(App),
}).$mount('#app')
5.在package.json中编写打包命令
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    "plug": "vue-cli-service build --target lib --name domTest --dest lib src/components/index.js" //打包命令
  },
6.运行npm run plug生成插件,上传到npm上
 

 

 

posted @ 2022-04-10 10:56  关关大大  阅读(312)  评论(0编辑  收藏  举报