mintUI配合vue2.0,webpack,vue-cli脚手架从零搭建

虽然vue-cli脚手架很方便,但是有些配置还是不够,

所以个人配置了一个mintUI的移动端单页面模板,可以使用less,axios,mintUI等常用组件和loading.

还配置了一个elementUI的pc端单页面模板。

代码地址:https://gitee.com/LIULIULIU8/elementui_mintui__template_file

  运行说明:

    1、进入到文件夹,输入命令行:cnpm install  初始化下载

    2、运行 cnpm run dev  ;即可打开访问

好用给个star哦!!

 

 

步骤说明:

 
  
 
  

1.确保安装了vue-cli
安装:cnpm install vue-cli -g
验证版本:vue --version

 
  

2.生成项目模板:
vue init webpack-simple mintui-case-wxactivity

 
  

3.进入项目目录
初始化:cnpm install
运行:cnpm run dev

 
  

4.下载引入vueRouter,并使用
下载:cnpm install vue-router --save-dev
引入:import VueRouter from 'vue-router'
注册:Vue.use(VueRouter);
配置路径:
const routes = [
{path:'/',component:home}
];

 
  

const router = new VueRouter({
// linkActivity:'active',
routes:routes
})

 
  

5.初始化Vue
new Vue({
router:router,
el: '#app',
render: h => h(App)
})

 
  

6.安装使用mintUI
安装:cnpm install mint-ui -save
引入使用:
//引入全部组件
import Mint from 'mint-ui'
import 'mint-ui/lib/style.css' //注意,此处样式要单独引入。
Vue.use(Mint);
//按需引入部分组件
import {Button} from 'mint-ui'
import 'mint-ui/lib/button/style.css'
Vue.component(Button.name,Button);

7.下载并使用less
安装:$ cnpm install less less-loader --save
配置webpack.config
{
test:/\.less$/,
loader:'style-loader!css-loader!less-loader'
},

 
  

8.下载并使用axios
安装:cnpm install axios --save
配置:在api文件中
使用:在某组件中,按需引入需要的接口请求 例:import {requestLogin} from '../api/'

 

 

main.js:

import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'

//引入全部组件
    // import Mint from 'mint-ui'
    // import 'mint-ui/lib/style.css'
//按需引入部分组件
import {Button} from 'mint-ui'
import 'mint-ui/lib/button/style.css'
Vue.component(Button.name,Button);



// 引入组件
import home from './components/Home.vue'
//注册
Vue.use(VueRouter);


const routes = [
  {path:'/',component:home}
];

const router = new VueRouter({
  // linkActivity:'active',
  routes:routes
})




new Vue({
  router:router,
  el: '#app',
  render: h => h(App)
})

 

webpack.config.js

var path = require('path')
var webpack = require('webpack')

module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js'
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'vue-style-loader',
          'css-loader'
        ],
      },      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
          }
          // other vue-loader options go here
        }
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test:/\.less$/,
        loader:'style-loader!css-loader!less-loader'
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      }
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    },
    extensions: ['*', '.js', '.vue', '.json']
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true,
    overlay: true
  },
  performance: {
    hints: false
  },
  devtool: '#eval-source-map'      //开发模式时打开
}

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map'
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      sourceMap: true,
      compress: {
        warnings: false
      }
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  ])
}

 

转载于:https://www.cnblogs.com/LChenglong/p/8033694.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值