import Toolbar from ‘./toolbar/index‘;
// 存储组件列表
const components = [
Toolbar
]
// 定义 install 方法,接收 Vue 作为参数。如果使用 use 注册插件,则所有的组件都将被注册
const install = function (Vue) {
// 判断是否安装
if (install.installed) return
// 遍历注册全局组件
components.map(component => Vue.component(component.name, component))
}
// 判断是否是直接引入文件
if (typeof window !== ‘undefined‘ && window.Vue) {
install(window.Vue)
}
export default {
// 导出的对象必须具有 install,才能被 Vue.use() 方法安装
install,
// 以下是具体的组件列表
Toolbar,
}
最后一步
package.json文件中添加命令
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"lib": "vue-cli-service build --target lib --name my --dest lib packages/index.js"
},
最后运行 npm run lib 就发现多了一个lib文件夹 里面就存放的你打包好的js以及css