第一步:创建一个自己的项目
vue init webpack-simple <project-name>
第二部:下载依赖
npm install 或者 cnpm install
第三步:创建自己的组件(页面输出一段话,随便写的)
1、目录结构如下,name与以后引用名称一致
2、index.js中内容
import Loading from './loading.vue'
export default Loading
第四步:base文件夹下index.js写入代码
import Loading from './components/loading'
const components = {
Loading
}
const jeremyui = {
...components
}
const install = function(Vue) {
if (install.installed) return
Object.keys(jeremyui).forEach(key => {
Vue.component(key, jeremyui[key])
})
}
if (typeof window !== 'undefined' && window.Vue) {
install(window.Vue)
}
const API = {
...components,
install
}
export default API;
第五步:修改webpack.config.js
1、entry修改为’./src/base/index.js’
2、output修改为(library 配置导出库的名称)
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
filename: 'loading.min.js',
library: 'anchordemo',
libraryTarget: 'umd'
第六步:修改package.json
1、“private”: true, 改为false
2、添加"main": “dist/loading.min.js”,
3、添加
“files”: [
“dist”,
“src/*”
],