一、初始化一個vue項目/vue init webpack ,能夠把多餘的文件刪除。只保留下面javascript
二、修改package.jsoncss
{ "name": "ggg-ui", "description": "A Vue.js project", "version": "1.1.1", "author": "guowf <380482989@qq.com>", "license": "MIT", "private": false, "scripts": { "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot", "build": "webpack --display-error-details --config webpack.config.js" }, "dependencies": { "vue": "^2.5.11" }, "browserslist": [ "> 1%", "last 2 versions", "not ie <= 8" ], "devDependencies": { "babel-core": "^6.26.0", "babel-loader": "^7.1.2", "babel-preset-env": "^1.6.0", "babel-preset-stage-3": "^6.24.1", "cross-env": "^5.0.5", "css-loader": "^0.28.7", "file-loader": "^1.1.4", "vue-loader": "^13.0.5", "vue-template-compiler": "^2.4.4", "webpack": "^3.6.0", "webpack-dev-server": "^2.9.1" }, "main": "/dist/gggUi.js", "repository": { "type": "git", "url": "https://github.com/13714273163/ggg-vue-ui.git" } }
三、根目錄新建webpack.config.js文件內容以下html
var path = require('path') var webpack = require('webpack') module.exports = { entry: './src/index.js', output: { path: path.resolve(__dirname, './dist'), publicPath: '/dist/', filename: 'gggUi.js', // 咱們可不想打包後叫build.js 多low啊 起一個與項目相對應的 library: 'gggUi', // library指定的就是你使用require時的模塊名,這裏即是require("PayKeyboard") libraryTarget: 'umd', //libraryTarget會生成不一樣umd的代碼,能夠只是commonjs標準的,也能夠是指amd標準的,也能夠只是經過script標籤引入的。 umdNamedDefine: true // 會對 UMD 的構建過程當中的 AMD 模塊進行命名。不然就使用匿名的 define。 }, module: { rules: [{ test: /\.css$/, use: [ 'vue-style-loader', 'css-loader' ], }, { test: /\.vue$/, loader: 'vue-loader', options: { loaders: {} // other vue-loader options go here } }, { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ }, { test: /\.(png|jpg|gif|svg)$/, loader: 'file-loader', options: { name: '[name].[ext]?[hash]' } } ] }, resolve: { alias: { 'vue$': 'vue/dist/vue.esm.js' }, extensions: ['*', '.js', '.vue', '.json'] }, devServer: { historyApiFallback: true, noInfo: true, overlay: true }, performance: { hints: false }, devtool: '#eval-source-map' } if (process.env.NODE_ENV === 'production') { module.exports.devtool = '#source-map' // http://vue-loader.vuejs.org/en/workflow/production.html module.exports.plugins = (module.exports.plugins || []).concat([ new webpack.DefinePlugin({ 'process.env': { NODE_ENV: '"production"' } }), new webpack.optimize.UglifyJsPlugin({ sourceMap: true, compress: { warnings: false } }), new webpack.LoaderOptionsPlugin({ minimize: true }) ]) }
四、修改.gitignore文件vue
切記要把dist加上註釋,否則沒把dist傳上去java
五、個人src文件參考node
其中index.js是總的文件出口,pachages下面的index是各個文件的出口(也就是element能夠一次性導入或者按需導入的作法)webpack
五、打包:npm run build /發佈:npm publish git
六、在新項目引用試試github
main.jsweb
xx.vue
效果圖