700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > vue cli3+项目使用postcss-px2rem或者postcss-plugin-px2rem适配

vue cli3+项目使用postcss-px2rem或者postcss-plugin-px2rem适配

时间:2020-12-18 02:03:42

相关推荐

vue cli3+项目使用postcss-px2rem或者postcss-plugin-px2rem适配

1. 使用postcss-px2rem或者postcss-plugin-px2rem讲vue项目的px全部转换未rem适配。

2. 下载:

npm install --savepostcss-px2remnpm install --savepostcss-plugin-px2rem

3. 使用:在vue.config.js中

module.exports = {publicPath: process.env.NODE_ENV === 'production' ? '/online/' : '/',// outputDir: 在npm run build时 生成文件的目录 type:string, default:'dist'// outputDir: 'dist',// pages:{ type:Object,Default:undfind }runtimeCompiler: true,devServer: {port: 8888, // 端口号host: 'localhost',https: false, // https:{type:Boolean}open: false, //配置自动启动浏览器//proxy: 'http://172.20.10.9:8080', // 配置跨域处理,只有一个代理proxy: {'/auidt': {target: 'http://172.20.10.9:8080',ws: true,changeOrigin: true},}, // 配置多个代理},css: {loaderOptions: {postcss: {plugins: [// require('postcss-px2rem')({ //配置postcss-px2rem适配//remUnit:100// })require('postcss-plugin-px2rem')({ //配置postcss-plugin-px2rem适配rootValue: 100, //换算基数, 默认100 ,这样的话把根标签的字体规定为1rem为50px,这样就可以从设计稿上量出多少个px直接在代码中写多上px了。unitPrecision: 5, //允许REM单位增长到的十进制数字。//propWhiteList: [], //默认值是一个空数组,这意味着禁用白名单并启用所有属性。// propBlackList: [], //黑名单exclude: /(node_module)/, //默认false,可以(reg)利用正则表达式排除某些文件夹的方法,例如/(node_module)/ 。如果想把前端UI框架内的px也转换成rem,请把此属性设为默认值// selectorBlackList: [], //要忽略并保留为px的选择器// ignoreIdentifier: false, //(boolean/string)忽略单个属性的方法,启用ignoreidentifier后,replace将自动设置为true。// replace: true, // (布尔值)替换包含REM的规则,而不是添加回退。mediaQuery: false, //(布尔值)允许在媒体查询中转换px。// minPixelValue: 3 //设置要替换的最小像素值(3px会被转rem)。 默认 0}),]}}}}

4. 注意:

4.1 如果页面这样配置页面全部被缩放很小。需要全局设置一个css:html,body的font-size为100px或者100PX。

html,body{font-size: 100PX;}

4.2 设置好了页面标签都需要设置宽高。或者设置display:flex。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。