1、在package.json同级目录下目录下创建一个index.js文件
import conHeader from "@/components/conHeader";
// // 这一步判断window.Vue是否存在,因为直接引用vue.min.js, 它会把Vue绑到Window上,我们直接引用打包好的js才能正常跑起来。
import _Vue from "vue";
conHeader.install = Vue => {
if (!Vue) {
window.Vue = Vue = _Vue;
}
Vue.component(conHeader.name, conHeader);
};
export default conHeader;
2、在package.json文件添加
"scripts": {
"lib": "vue-cli-service build --target lib --name con-header --dest lib index.js",
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
运行 npm run lib即可生成