行业知识
移动端的React项目中如何配置自适应和px转rem
2026-11-02 13:39:48
来源:互联网转载
创建项目
create-react-app project-name
()启动项目
npm start
下载自适应和px转rem的插件
�index.php/tags-41973.html" >��适应的: npm install lib-flexible --save
()px转rem的:npm install postcss-pxtorem@5.1.1 --save-dev
创建craco.config.js配置文件
在package.json中配置craco
"scripts": { "start": "craco start", "build": "craco build", "test": "craco test", "eject": "craco eject" } 在craco.config.js文件中配置 postcss-pxtorem
const path = require('path')module.exports = { // 配置@符号的 webpack: { alias: { '@': path.join(__dirname, 'src') } }, style: { // 配置postcss-pxtorem postcss: { mode: 'extends', loaderOptions: { postcssOptions: { ident: 'postcss', plugins: [ [ 'postcss-pxtorem', { rootValue: 375 / 10, // 根元素字体大小 // propList: ['width', 'height'] propList: ['*'] }, ], ], }, }, }, },}
上一篇:服务器怎么改语言?
下一篇:英语表达中的五大技巧揭秘!