項目初始化
使用 webpack-simple 方式比較方便和容易配置,原來的方式各類坑慎入html
vue init webpack-simple vue-card-slide cd vue-card-slide npm run dev
項目結構以下所示vue
更改webpack.config.js配置webpack
entry: './src/lib/index.js', output: { path: path.resolve(__dirname, './dist'), publicPath: '', filename: 'vue-card-slide.js', library: 'VueCardSlide', libraryTarget: 'umd', umdNamedDefine: true}
修改package.jsongit
"name": "vue-card-slide", "description": "A vue plugin for Carousel Card Slide", "version": "1.1.1", "author": "carrie ", "license": "MIT", "private": false, "main": "dist/vue-card-slide.js", "repository": { "type": "git", "url": "https://github.com/Carrie999/vue-card-slide/" }
修改index.html
src="/dist/build.js" 改爲 src="/dist/vue-card-slide.js"
封裝打包好本身的插件 上傳到相應git地址github
npm 註冊 npm login npm publish 就打包上傳成功了web
// ES6引入 import cardSlide from 'vue-card-slide' // require引入 var cardSlide = require('CardSlide') Vue.use(cardSlide)// 組件中使用
附上git地址戳我npm