配置postcss-pxtorem报:options has an unknown property 'plugins'
闲聊:
小颖最近在坐大屏相关的项目,要写适配,之前用的:postcss-px2rem、px2rem-loader,和朋友闲聊呢他说他们也在写大屏,不过他们用的 postcss-pxtorem,在写另外一个项目时,小颖就想着试试 postcss-pxtorem ,结果配置到 vue.config.js 后就报错················如下图所示:

报错分析及解决方案:
vue项目安装使用postcss-pxtorem,在vue.config.js中进行配置,需要注意vue-cli-service的版本。如若vue-cli-service的版本为4,可直接在vue.config.js中进行配置。代码如下:
const { defineConfig } = require('@vue/cli-service')
const name = process.env.VUE_APP_TITLE || 'xxxxx' // 网页标题
const pxtorem = require('postcss-pxtorem');
module.exports = defineConfig({
transpileDependencies: true,
configureWebpack: { name: name, },
css: {
loaderOptions: {
sass: {
sassOptions: { outputStyle: "expanded" }
},
postcss: {
plugins: [
pxtorem({
rootValue: 37.5,
propList: ['*'],
}),
]
}
}
}
})
如若vue-cli-service的版本为5,则按以上配置无效,将 vue.config.js 中的 postcss 配置修改成下面的配置
const { defineConfig } = require('@vue/cli-service')
const name = process.env.VUE_APP_TITLE || 'xxxx' // 网页标题
const pxtorem = require('postcss-pxtorem');
module.exports = defineConfig({
transpileDependencies: true,
configureWebpack: { name: name, },
css: {
loaderOptions: {
sass: {
sassOptions: { outputStyle: "expanded" }
},
postcss: {
postcssOptions: {
plugins: [
pxtorem({
rootValue: 37.5,
propList: ['*'],
}),
],
}
}
}
}
})
相关内容:
在vue项目中如何解决适配问题:
方案一:使用 postcss-pxtorem 插件
1.下载插件
npm i postcss-pxtorem@5.1.1 -D
2.在 utils 文件 中创建 rem.js
const baseSize = 16
function setRem() {
const scale = document.documentElement.clientWidth / 1920
let fontSize = (baseSize * Math.min(scale, 2)) > 12 ? (baseSize * Math.min(scale, 2)) : 12
document.documentElement.style.fontSize = fontSize + 'px'
}
setRem()
window.onresize = function () {
setRem()
}
3.在 main.js 中引入 rem.js
import './utils/rem'//屏幕适配
方案二:使用 postcss-px2rem、px2rem-loader 插件
希望对大家有所帮助呦·································
配置postcss-pxtorem报:options has an unknown property 'plugins'的更多相关文章
- options has an unknown property 'modifyVars'. These properties are valid: 处理方法
webpack 编译时提示 ValidationError: Invalid options object. Less Loader has been initialized using an opt ...
- Nginx配置SSL报错 nginx: [emerg] unknown directive "ssl"
Nginx配置SSL报错 nginx: [emerg] unknown directive "ssl" 出现如图所示错误,处理办法如下 去nginx解压目录下执行 ./co ...
- 疑难杂症:org.hibernate.MappingException: Unknown entity,annotation配置Entity类报错
引言: 夜声人静,外面下着稀里哗啦的雨,周末的晚上,还在键盘上舞动手指. 此刻很感激一个人一篇随笔,感谢xiaochao以及他的<org.hibernate.MappingException: ...
- nuxt/eapress 安装报错Module build failed: ValidationError: PostCSS Loader Invalid OptionsModule build failed: ValidationError: PostCSS Loader Invalid Options options['useConfigFile'] is an invalid additi
错误信息: Module build failed: ValidationError: PostCSS Loader Invalid Options options['useConfigFile'] ...
- springboot 配置jpa启动报Error processing condition on org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration.pageableCustomizer
springboot +gradle 配置jpa启动报Error processing condition on org.springframework.boot.autoconfigure.data ...
- appium报错:An unknown server-side error occurred while processing the command. Original error: Could not proxy command to remote server. Original error: Error: read ECONNRESET
Appium Desktop版本:1.9.0 xcode版本:9.4.1 测试机:iPhone7 11.3系统 问题描述:在xcode上的produc的text运行是可以将WebDriverAgen ...
- 配置MySQL主从复制报错Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work
配置MySQL主从复制报错 ``` Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave ha ...
- 解决jira配置gmail邮箱报错
具体报错: AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at 535 ...
- Vue项目 invalid host header 问题 配置 disableHostCheck:true报错
项目场景: 解决 Vue 项目 invalid host header 问题disableHostCheck:true报错 问题描述 使用内网穿透时出现 invalid host header 找了好 ...
- - configuration.module has an unknown property 'loader' 问题解决
错误提示: Invalid configuration object. Webpack has been initialised using a configuration object that d ...
随机推荐
- 关于Openssh版本升级问题及版本升级到最新版8.7p1流程(CentOS7系统)
前言: 对linux服务器做过漏洞扫描的都知道,常常服务器会被扫出一大堆关于openssh的漏洞,诸如下面这些,而其中的原因就是因为openssh版本比较低.于是就需要升级openssh的版本.下面就 ...
- 基于CUBEMX的STM32F4 Hal库,配置LVGL(无操作系统版)
本篇文章移植思路适用于所有嵌入式MCU,包括Arm,STM32,NXP,乐鑫,Nuvoton,Arduino,RT-Thread,Zephyr,NuttX,Adafruit等等. 为什么要写这一篇移植 ...
- VMware虚拟机的安装与配置
一.VMware简介 VMware Workstation Pro 是业界标准的桌面 Hypervisor,用于在 Linux 或 Windows PC 上运行虚拟机. Workstation 16 ...
- Redis系列18:过期数据的删除策略
Redis系列1:深刻理解高性能Redis的本质 Redis系列2:数据持久化提高可用性 Redis系列3:高可用之主从架构 Redis系列4:高可用之Sentinel(哨兵模式) Redis系列5: ...
- cpu,gpu的种类
- BUGKU逆向reverse 1-8题
练习IDA两年半 打开尘封已久的bugku,从题目中练习使用,现在都已经是新版本了 orz 入门逆向 运行baby.exe将解压后的baby.exe拖到IDA里面主函数中找到mov指令 可以看到这里就 ...
- 架构师必会之-DBA级问题的数据库底层设计思想
大家好,我是sulny_ann,这期想跟大家分享一下我之前在面试里面问过比较难的数据库相关的问题. 大家经常也在调侃后端好像就是技术数据库的增删改查,所以作为后端开发,你对应数据库这一块掌握的怎么样, ...
- mybatis数据库字段自动填充
背景描述 目前,大多数项目的数据库设计,都会添加一些公共字段,比如version(版本号).deleted(逻辑删除标识).create_time.update_time.create_by.upda ...
- 如何像 Sealos 一样在浏览器中打造一个 Kubernetes 终端?
作者:槐佳辉.Sealos maintainer 在 Kubernetes 的世界中,命令行工具(如 kubectl 和 helm)是我们与集群交互的主要方式.然而,有时候,我们可能希望能够在 Web ...
- python爬虫——爬虫伪装和反“反爬”
前言爬虫伪装和反"反爬"是在爬虫领域中非常重要的话题.伪装可以让你的爬虫看起来更像普通的浏览器或者应用程序,从而减少被服务器封禁的风险:反"反爬"则是应对服务器 ...