VUX元件主要是用來做微信端的一些項目,合理利用vux元件可以讓我們的工作效率更高。
<1>. 在項目裡安裝vux
npm install vux --save (安裝到dependencies)
或者是 npm install vux --S
<2>. 安裝vux-loader (vux文檔中沒有明文跟你說要安裝)
npm install vux-loader --save-dev (安裝到devDependencies)
<3>. 安裝less-loader (這個是用以正确編譯less源碼,否則會出現 ' Cannot GET / ',自己看package.json,如果安裝了,就不用裝啦!)
npm install less less-loader --save-dev
<4>. 安裝yaml-loader (不用裝)
npm install yaml-loader --save-dev
<5>. 在build檔案夾下webpack.base.conf.js 檔案進行配置
const vuxLoader = require('vux-loader') 【新加上去的】
const webpackConfig = originalConfig 【originalConfig就是原來的 module.exports出去的代碼,把它整個指派給變量 webpackConfig】
module.exports = vuxLoader.merge(webpackConfig, { plugins: ['vux-ui'] }) 【在最後加多一句,這裡就是引用插件vux啦!】
'use strict' const path = require('path') const utils = require('./utils') const config = require('../config') const vueLoaderConfig = require('./vue-loader.conf') const vuxLoader = require('vux-loader') function resolve (dir) { return path.join(__dirname, '..', dir) } const createLintingRule = () => ({ test: /\.(js|vue)$/, loader: 'eslint-loader', enforce: 'pre', include: [resolve('src'), resolve('test')], options: { formatter: require('eslint-friendly-formatter'), emitWarning: !config.dev.showEslintErrorsInOverlay } }) let webpackConfig = { context: path.resolve(__dirname, '../'), entry: { app: './src/main.js' }, externals: { 'weui': 'weui', 'BMap': 'BMap', 'EZUIPlayer': 'EZUIPlayer', 'Stomp': 'Stomp', 'BMAP_ANCHOR_TOP_LEFT': 'BMAP_ANCHOR_TOP_LEFT', 'BMAP_ANCHOR_TOP_RIGHT': 'BMAP_ANCHOR_TOP_RIGHT', 'BMAP_ANCHOR_BOTTOM_RIGHT': 'BMAP_ANCHOR_BOTTOM_RIGHT', 'BMAP_ANCHOR_BOTTOM_LEFT': 'BMAP_ANCHOR_BOTTOM_LEFT', 'BMAP_NAVIGATION_CONTROL_SMALL': 'BMAP_NAVIGATION_CONTROL_SMALL', }, output: { path: config.build.assetsRoot, filename: '[name].js', publicPath: process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath }, resolve: { extensions: ['.js', '.vue', '.json'], alias: { 'vue$': 'vue/dist/vue.esm.js', '@': resolve('src'), 'api': path.resolve(__dirname, '../src/api'), } }, module: { rules: [ ...(config.dev.useEslint ? [createLintingRule()] : []), { test: /\.vue$/, loader: 'vue-loader', options: vueLoaderConfig }, { test: /\.js$/, loader: 'babel-loader', include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')] }, { test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('img/[name].[hash:7].[ext]') } }, { test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('media/[name].[hash:7].[ext]') } }, { test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('fonts/[name].[hash:7].[ext]') } } ] }, node: { // prevent webpack from injecting useless setImmediate polyfill because Vue // source contains it (although only uses it if it's native). setImmediate: false, // prevent webpack from injecting mocks to Node native modules // that does not make sense for the client dgram: 'empty', fs: 'empty', net: 'empty', tls: 'empty', child_process: 'empty' } } module.exports = vuxLoader.merge(webpackConfig, { plugins: ['vux-ui'] })
<6>最後别忘了,在resolve: {
extensions: ['.js', '.vue', '.json','.less']裡加入.less。
https://www.jianshu.com/p/930d9bb22736