- 安装vue-cli3脚手架
- 安装脚手架
npm install -g @vue/cli
- 创建项目
vue create my-project
- 安装vant
npm install vant -S
- 安装babel-plugin-import插件(按需加载)
# 安装插件
npm i babel-plugin-import -D`
- babel.config.js文件里配置
// 对于使用 babel7 的用户,可以在 babel.config.js 中配置
module.exports = {
presets: [
'@vue/app'
],
plugins: [
['import', {
libraryName: 'vant',
libraryDirectory: 'es',
style: true
}, 'vant']
]
};
// 接着你可以在代码中直接引入 Vant 组件
// 插件会自动将代码转化为方式二中的按需引入形式
// import { Button } from 'vant';
- vant rem适配,需要安装两个插件
postcss-pxtorem 是一款 postcss 插件,用于将单位转化为 rem
lib-flexible 用于设置 rem 基准值
npm install postcss-pxtorem --save-dev
npm i -S amfe-flexible
main.js 引入amfe-flexible
import 'amfe-flexible/index.js'
- 在postcss.config.js文件内(没有就在根目录创建一个)
//修改前:
module.exports = {
plugins: {
}
}
//修改后
// module.exports = {
// plugins: {
// 'autoprefixer': {
// browsers: ['Android >= 4.0', 'iOS >= 7']
// },
// 'postcss-pxtorem': {
// rootValue: 37.5,
// propList: ['*']
// }
// }
//}
// 最新写法
module.exports = {
plugins: {
'autoprefixer': {
overrideBrowserslist: [
'Android 4.1',
'iOS 7.1',
'Chrome > 31',
'ff > 31',
'ie >= 8'
]
},
'postcss-pxtorem': {
rootValue: 37.5,
propList: ['*']
}
}
}
- tip:1、375px 即100%宽度,写px会自动rem处理,如果不想被rem处理,可以使用PX来写。
留一份vue.config.js 文件
module.exports = {
// http://oss.hp-iot.cn/terminal/v1
publicPath: process.env.NODE_ENV === 'production' ? '/' : '/',
// outputDir: 在npm run build时 生成文件的目录 type:string, default:'dist'
// outputDir: 'dist',
// pages:{ type:Object,Default:undfind }
// chainWebpack: config => {
// // 取消prefetch和preload
// config.plugins.delete('preload')
// config.plugins.delete('prefetch')
// },
devServer: {
disableHostCheck: true, // 花生壳显示Invalid Host header让其不检查hostname。
https: false, // https:{type:Boolean}
open: false, // 配置自动启动浏览器
// proxy: 'http://localhost:4000' // 配置跨域处理,只有一个代理
// port: 80,
// host: 'wxtest.com',
proxy: {
'/api': {
target: 'http://192.168.0.222:8080/api',
ws: true,
changeOrigin: true,
pathRewrite: {
'^/api': '/'
}
}
} // 配置多个代理,
},
css: {
loaderOptions: {
sass: {
data: `
@import "@/assets/css/common.scss";
`
}
}
},
configureWebpack: {
performance: {
hints: 'warning',
// 入口起点的最大体积 整数类型(以字节为单位)
maxEntrypointSize: 50000000,
// 生成文件的最大体积 整数类型(以字节为单位 300k)
maxAssetSize: 30000000,
// 只给出 js 文件的性能提示
assetFilter: function (assetFilename) {
return assetFilename.endsWith('.js')
}
}
}
}
原文:https://blog.csdn.net/qq_37942845/article/details/90444784