Vue Vux

Vux是基于WeUI和Vue2开发的移动端UI组件库,主要服务于微信页面。

安装

$ npm i vue-cli -g
$ vue init airyland/vux2 projectPath
$ cd projectPath && npm i
$ npm run dev

$ npm i vux --save
$ npm i less less-loader --save-dev
# 安装webpack
$ npm i webpack -g
$ webpack -V

# 安装Vue脚手架
$ npm i vue-cli -g
$ vue -V

# 项目内安装Vuex
$ npm i vuex --save

# 创建项目
$ vue init airyland/vux2 webapp
$ cd webapp && npm i

$ npm i vux-loader --save-dev
$ npm i less less-loader --save-dev

$ npm run dev
$ npm i vuex-i18n -S

vux必须配置vux-loader使用,在build/webpack.base.config.js配置。

# build/webpack.base.config.js

const vuxLoader = require('vux-loader')
module.exports = vuxLoader.merge(webpackConfig, {
  plugins:[{name:'vux-ui'},{name:'duplicate-style'}]
})

# 完整版本
'use strict'
const path = require('path')
const utils = require('./utils')
const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf')


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'),
    // 不符合ESLint规则时警告提示,默认为运行出错。
    //emitWarning: !config.dev.showEslintErrorsInOverlay
  }
})

const webpackConfig = {
  context: path.resolve(__dirname, '../'),
  entry: {
    app: './src/main.js'
  },
  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', 'less'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src'),
    }
  },
  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]')
        },
      {
        test: /\.less$/,
        loader: 'style-loader!css-loader!less-loader'
      }
    ]
  },
  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'
  }
}

const vuxLoader = require('vux-loader')
module.exports = vuxLoader.merge(webpackConfig, {
  plugins:[{name:'vux-ui'},{name:'duplicate-style'}]
})

入口配置

$ vim src/main.js

import Vue from 'vue'
// 添加FastClick移除移动端点击延迟
import FastClick from 'fastclick'
// 添加前端路由
import router from './router'
import App from './App'

// 移除移动端点击延迟
FastClick.attach(document.body)
//日志输出开关
Vue.config.productionTip = true
new Vue({
  el: '#app',
  router,
  components: { App },
  template: ''
})

你可能感兴趣的:(Vue Vux)