React configuration px conversion rem method

React configuration px conversion rem method

Install related dependencies

npm i lib-flexible --save
npm i postcss-px2rem --save

Mainly used to expose project configuration

npm run eject
! If you run npm run eject and get an error, the error may be caused by the code in the repository not being submitted. Submit it as follows
git add .
git commit -m 'custom name'
npm run eject

Then open the project config->webpack.config.js for configuration

// Add the following two lines of code to the configuration file
// px2rem({ remUnit: 75 }) means 1rem = 75px. This is based on the 750px design draft. If it is 620, write 62

const px2rem = require('postcss-px2rem');
px2rem({ remUnit: 75 })

Set according to the design size, such as: 108 = 1080px/10

Import lib-flexible: Import the lib-flexible file into the entry file index.js

import 'lib-flexible'

Comment out the following code in the public->index.html file

Restart the project after configuration is complete

This is the end of this article about how to configure react to convert px to rem. For more information about how to configure react to convert px to rem, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of react inline style using webpack to convert px to rem
  • React Koa Rematch How to build a server-side rendering framework
  • Application of rem layout in react in JavaScript

<<:  MySql5.7.21 installation points record notes

>>:  Two ways to create SSH server aliases in Linux

Recommend

How to choose transaction isolation level in MySQL project

introduction Let's start with our content. I ...

Mysql multi-condition query statement with And keyword

MySQL multi-condition query with AND keyword. In ...

Using docker command does not require sudo

Because the docker daemon needs to bind to the ho...

MySQL 5.5 installation and configuration graphic tutorial

Organize the MySQL 5.5 installation and configura...

Analyze the method of prometheus+grafana monitoring nginx

Table of contents 1. Download 2. Install nginx an...

What are your principles for designing indexes? How to avoid index failure?

Table of contents Primary key index Create indexe...

Script to quickly list all host names (computer names) in the LAN under Linux

Recently, I have a need to list all host names in...

How to use @media in mobile adaptive styles

General mobile phone style: @media all and (orien...

Common interview questions and answers for web designer positions

1. What are the templates for ASP.NET Web applicat...

React implements the addition, deletion, modification and query of todolist

Table of contents Take todolist as an example The...

JS implements the sample code of decimal conversion to hexadecimal

Preface When we write code, we occasionally encou...

HTML table markup tutorial (43): VALIGN attribute of the table header

In the vertical direction, you can set the alignm...

Let's learn about the MySQL storage engine

Table of contents Preface 1. MySQL main storage e...

VUE+Express+MongoDB front-end and back-end separation to realize a note wall

I plan to realize a series of sticky note walls. ...