{
"presets": [
["es2015", { "modules": false }]
],
"plugins": [["component", [
{
"libraryName": "mint-ui",
"style": true
}
]]]
}
./
|-- dist
| `-- bundle.js
|-- index.html
|-- src
| |-- components
| | |-- app.vue
| | |-- header.vue
| | |-- index.vue
| | `-- login.vue
| |-- css
| | |-- index.css
| | `-- mui
| |-- img
| | `-- bg2.jpg
| |-- main.js
| `-- routes.js
`-- webpack.config.js
const path=require("path") //node.js中用于识别路径的包
const VueLoaderPlugin = require('vue-loader/lib/plugin') //用于打包Vue组件的插件
module.exports={
mode:'development', //设置开发模式
entry: path.join(__dirname,"src/main.js"), //入口文件
output:{
path:path.join(__dirname,"dist"), //出口文件和文件名
filename:"bundle.js"
},
devServer:{ //使用webpack-dev-server进行实时监控
port:8081, //展示的端口
host:'0.0.0.0', //外部主机可以访问
disableHostCheck: true, //避免安全检查
contentBase:path.join(__dirname,"/"), //设置展示的初始路径
hot:true //启用热重载
},
module:{
rules:[
{
test:/\.css$/,
use:[
{loader:'vue-style-loader'}, //定义css文件的处理规则,这里具有固定的加载顺序
{loader:'css-loader'}
]
},
{test:/\.(jpg|png|gif|jpeg)$/,use: 'url-loader?limit=102400&name=[name].[ext]'}, //处理url类型资源和图片的base64压缩处理
{test:/\.vue$/,use:'vue-loader'}, //
{test:/\.js$/,use:'babel-loader'}
]
},
plugins:[
new VueLoaderPlugin() //vue打包必须
],
resolve:{
alias:{
vue$:"vue/dist/vue.js" //处理在main中引用vue的问题
}
}
}
//Vue 入口文件
import Vue from 'vue'
import {Header, Tabbar, TabItem} from 'mint-ui'
import 'mint-ui/lib/style.css' //自动去node_modules下找
//app组件文件
import appEntry from './components/app.vue'
Vue.component(Header.name,Header)
Vue.component(Tabbar.name,Tabbar)
Vue.component(TabItem.name,TabItem)
//替换html模板x
var template=`
<App></App>
`
//将app组件挂载到实例对象中
var app=new Vue({
el:"#app",
template:template,
components: {
'App':appEntry
}
})
<template>
<div class="app-container">
<!-- 顶部内容 mint-ui组件 -->
<mt-header fixed :title="header"></mt-header>
<router-view></router-view>
<!-- 底部内容 -->
<mt-tabbar v-model="selected">
<mt-tab-item v-for="item in data1" :id="item.content" :key="item.id" >
<img slot="icon" >
{{item.content}}
</mt-tab-item>
</mt-tabbar>
</div>
</template>
<script>
export default {
data:function(){
return{
header:"hello Vue!",
data1:[{
id:0,
content:"外卖"
},{
id:1,
content:"订单"
},{
id:2,
content:"发现"
},{
id:3,
content:"我的"
}
],
selected:''
}
}
}
</script>
<style scoped>
</style>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>webpack</title>
<link rel="stylesheet" href="">
</head>
<body>
<div id="app">
</div>
</body>
<script type="text/javascript" src="/bundle.js"></script>
</html>
5.2 根据.gitignore规则添加文件到本地git