雖然vue-cli腳手架很方便,可是有些配置仍是不夠,css
因此我的配置了一個mintUI的移動端單頁面模板,能夠使用less,axios,mintUI等經常使用組件和loading.html
還配置了一個elementUI的pc端單頁面模板。vue
代碼地址:https://gitee.com/LIULIULIU8/elementui_mintui__template_filenode
運行說明:webpack
一、進入到文件夾,輸入命令行:cnpm install 初始化下載ios
二、運行 cnpm run dev ;便可打開訪問git
好用給個star哦!!web
步驟說明:vue-router
1.確保安裝了vue-cli
安裝:cnpm install vue-cli -g
驗證版本:vue --versionvue-cli
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 }) ]) }