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

Oracle deployment tutorial in Linux environment

1. Environment and related software Virtual Machi...

The meaning and calculation method of QPS and TPS of MySQL database

When doing DB benchmark testing, qps and tps are ...

How to use docker to build redis master-slave

1. Build a Docker environment 1. Create a Dockerf...

Eight rules for effective web forms

If you're collecting information from your us...

Web page printing thin line table + page printing ultimate strategy

When I was printing for a client recently, he aske...

Bootstrap realizes the effect of carousel

This article shares the specific code of Bootstra...

How to reduce memory usage and CPU usage of web pages

Some web pages may not look large but may be very...

How to implement vertical text alignment with CSS (Summary)

The default arrangement of text in HTML is horizo...

How to set up scheduled backup tasks in Linux centos

Implementation Preparation # Need to back up the ...

A brief discussion on the three major issues of JS: asynchrony and single thread

Table of contents Single thread asynchronous Sing...

Use of nginx custom variables and built-in predefined variables

Overview Nginx can use variables to simplify conf...

How to use history redirection in React Router

In react-router, the jump in the component can be...

JS realizes video barrage effect

Use ES6 modular development and observer mode to ...

How to change the root password in a container using Docker

1. Use the following command to set the ssh passw...