三分钟学会 vux
三分钟学会vux
<1>. 在项目里安装vux
npm install vux –save
<2>. 安装vux-loader (这个vux文档似乎没介绍,当初没安装结果报了一堆错误)
npm install vux-loader –save-dev
<3>. 安装less-loader (这个是用以正确编译less源码,否则会出现 \’ Cannot GET / \’)
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
// 原来的 module.exports 代码赋值给变量 webpackConfig,
//即将原来的module.exports 改为 const webpackConfig
module.exports = vuxLoader.merge(webpackConfig, { plugins: [\’vux-ui\’] })
<6>最后别忘了,在resolve: {
extensions: [\’.js\’, \’.vue\’, \’.json\’,\’.less\’]里加入.less。
二:webpack.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 = { 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\'],//vux加上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, { options:{}, plugins: [\'vux-ui\'] })
index.js文件如下:
import Vue from \'vue\' import Router from \'vue-router\' import HelloWorld from \'@/components/HelloWorld\' import app1 from \'@/components/app1\' //vux配置 import VueRouter from \'vue-router\' Vue.use(VueRouter) Vue.use(Router) export default new Router({ routes: [ { path: \'/\', name: \'HelloWorld\', component: HelloWorld }, { path: \'/app1\', name: \'app1\', component: app1 } ] })
main.js文件如下:
// The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from \'vue\' import App from \'./App\' import router from \'./router\' Vue.config.productionTip = false /* eslint-disable no-new */ new Vue({ el: \'#app\', router, components: { App }, template: \'<App/>\' })
app1.vue文件如下:
<template> <div> <group> <cell title="title" value="value"></cell> </group> </div> </template> <script> import { Group, Cell } from \'vux\' export default { name: "app1", components: { Group, Cell } } </script> <style scoped> </style>