Create-react-app Project Add less configuration

Source: Internet
Author: User
Tags postcss

Using the create-react-app project created by default is not supported less , the following steps to increase less the configuration

Exposing configuration Files

create-react-appThe generated project text, do not see the Webpack related configuration file, need to be exposed first, use the following command:

NPM Run Eject
Installation less-loaderAnd less
NPM Install Less-loader less--save-dev
Modify webpackConfiguration

modifying and webpack.config-prod.js configuring files

Change 1:

/\.css$/Instead /\.(css|less)$/, , modify the following:

Exclude: [  /\.html$/,  /\. ( JS|JSX) $/,  /\. ( css|less) $/,  /\.json$/,  /\.bmp$/,  /\.gif$/,  /\.jpe?g$/,  /\.png$/,],


Change 2:

  • test: /\.css$/Switch/\.(css|less)$/
  • test: /\.css$/usearray configuration is increasedless-loader
  • The following changes are followed:
  • {test:/\. (css|less) $/, use: [Require.resolve (' Style-loader '), {loader:require.resolve (' Css-loader '), Options: {importloaders:1,},}, {Loader:require.resolve (' Postcss-loader '), options: {//necessary for external CSS imports to work        // ' Postcss ', Plugins: ()=[Require (' Postcss-flexbugs-fixes '), Autoprefixer ({browsers: [' >1% ',              ' Last 4 versions ',              ' Firefox ESR ',              ' Not IE < 9 ',//React doesn ' t support IE8 anyway], Flexbox:' no-2009 ',} ),],},}, {Loader:require.resolve (' Less-loader ')//compiles less to CSS    }  ],},

Create-react-app Project Add less configuration

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.