vux安装指南

1、安装vue-cli脚手架

1.1、npm install --global vue-cli

1.2、vue init webpack newVue

1.3、cd newVue

1.4、npm run dev

2、vux安装

2.1在项目里安装vux

npm install vux --save

2.2安装vux-loader  (这个vux文档似乎没介绍,当初没安装结果报了一堆错误) 

npm install vux-loader --save-dev

2.3安装less-loader (这个是用以正确编译less源码,否则会出现 ' Cannot GET / ',自己看package.json,如果安装了,就不用装啦!)

npm install less less-loader --save-dev

2.4安装yaml-loader  (以正确进行语言文件读取, 我没安装似乎也没报错)

npm install yaml-loader --save-dev

2.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啦!】

最后别忘了,在resolve: {

extensions: ['.js', '.vue', '.json','.less']里加入.less。

2.6webpack.base.conf.js 完整代码(加粗项是更改内容)

'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 webpackConfig = {  //  module.exports替换成 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: [

      {

        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']

})

项目报错问题

this.$t is not a function,"$t" is not defined 

vux在安装的时候是使用的国内镜像cnpm,导致某些依赖出现问题。将工程中的node_modules文件夹删掉,然后使用npm install命令重新安装依赖,问题得到解决

你可能感兴趣的:(vux安装指南)