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 dynamically add a volume to a running Docker container

Someone asked me before whether it is possible to...

Detailed explanation of two ways to dynamically change CSS styles in react

The first method: dynamically add a class to show...

JS achieves five-star praise case

This article shares the specific code of JS to ac...

Detailed explanation of nginx upstream configuration and function

Configuration Example upstream backend { server b...

MySQL trigger usage scenarios and method examples

trigger: Trigger usage scenarios and correspondin...

Let me teach you how to use font icons in CSS

First of all, what is a font icon? On the surface...

Web development tutorial cross-domain solution detailed explanation

Preface This article mainly introduces the cross-...

Continuous delivery using Jenkins and Docker under Docker

1. What is Continuous Delivery The software produ...

Complete steps to install Anaconda3 in Ubuntu environment

Table of contents Introduction to Anaconda 1. Dow...

HTML CSS3 does not stretch the image display effect

1. Use the transform attribute to display the ima...