vux组件的引入及简单使用

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
 

你可能感兴趣的:(VUE)