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上