About React scaffolding uses ANTD for styles to be introduced on demand, and custom themes

tags: react.js

About React scaffolding uses ANTD for styles to be introduced on demand, and custom themes

The display is written according to the official website 3.x version, it is not feasible, and the error has been reported
Then I went to Github to check React-APP-Rewired and Customize-CRA.
Repeat the less-loader, change the version, or report an error
Because I want to set and customize the theme color on demand at the same time, and the official documentation of the 4.x version only says how to use@Craco-Craco and Craco-Less to achieve custom themes. I need to be imported, which confuses me

Thinking for a long time:
Because the place where the error reports has always been adDLessLoader (introduced from Customize-CRA)
so,Until I saw this sentence on the official website 3.x version, I changed my mind, without Customize-CRA, switch to@Craco/Craco Bebal-Plugin-IMPORT


Then learn from this article:
https://blog.csdn.net/qq_41580536/article/details/120429472

Configure the following code in Craco.config.js:

const CracoLessPlugin = require('craco-less')
module.exports = {
  babel: {   // Set style to import on demand
    plugins: [
      [
        "import",
        {
          "libraryName": "antd", 
          "libraryDirectory": "es",
          "style": true  // true indicates that it is less
        }
      ]
    ]
  },
  plugins: [
    {
      plugin: CracoLessPlugin,
      options: {  // Change the theme color
        lessLoaderOptions: {
          lessOptions: {
            modifyVars: { '@primary-color': '#e02342' },
            javascriptEnabled: true, // Set the allowable code modification configuration
          },
        },
      },
    },
  ],
}

Change the package.json configuration file as follows:

"scripts": {
    "start": "craco start",
    "build": "craco build",
    "test": "craco test",
    "eject": "react-scripts eject"
  },

Successful settings! Intersection Intersection Intersection Intersection

Intelligent Recommendation

React official scaffolding ANTD style implementation on-demand

React Official Scaffold ANTD Sites loading First method Babel-plugin-import At this time, it will be prompted, the command is not reversible, whether to continue, enter Y, so all configuration items c...

AntD imported in React is automatically introduced on demand

AntD imported in React is automatically introduced on demand The main ones used here arereact-app-rewiredwithcustomize-cra becausereact-app-rewiredin2.0Later versions willinjectBabelPluginMethod is de...

create-react-app scaffolding realizes on-demand loading of antd or antd-mobile

Implement create-react-app scaffolding to integrate antd and antd-mobile on-demand loading The first step is to build the project Run the command to build the project, the old version is to install cr...

When React uses ANTD, the CSS is introduced on demand - the pro test is effective, currently using version 4.10.0

CSS in need Install Customize-CRA, Babel-Plugin-Import and React-App-Rewired Scripts configuration items in the package.json file are modified to Create a config-overrides.js file in the root of the p...

VITE ELEMENT-PLUS Custom themes are introduced on demand not to take effect

> Public account search: front -end person 1. Use the official CLI theme tool to compile SASS as a CSS file (Node version v10.24.1) (1): The CLI tool for the global installation (2): Modify the the...

More Recommendation

create-react-app scaffolding to create a react project, introducing less support + antd on-demand loading + custom theme two ways

Because antd's css is based onlessDeveloped, although it can be used by introducing css, but this can’t modify the antd theme, which may be a little inconvenient.Modify the theme of antdYou need...

Custom styles and themes

#Style and theme (emphasis) ##01_ style: mainly on the control, modify some properties of the control; Custom style: ##02_ Code: <?xml version="1.0" encoding="utf-8"?> Custom...

Custom themes and styles in Android

The effect is as follows: Set the theme and style through the xml file: Style file custom style and theme code: xml file:...

React introduces ANTD and configures on-demand and custom theme

Download component library package Use CRACO to customize CREATE-React-APP The root directory creates a cRaco.config.js file Change package.json Implement on-demand packaging CRACo.config.js Add Imple...

React uses ANTD, LESS style on demand

React Using ANTD, LESS Pattern on-demand Download Dependency Module 2. Configure config-overrides.js in the root directory The specific configuration is as follows: 3. Modify the Pack.json related con...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top