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
    })
  ])
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM