• react中自定义antd主题与支持less(第二部)


    自定义主题

    首先自定义主题需要修改antd,antd本身也是less写的之后编译成css的,所以当我们需要使用less。

    1.yarn add react-app-rewire-less --dev

    const { injectBabelPlugin } = require('react-app-rewired');
    + const rewireLess = require('react-app-rewire-less');
    
      module.exports = function override(config, env) {
    -   config = injectBabelPlugin(['import', { libraryName: 'antd', style: 'css' }], config);
    +   config = injectBabelPlugin(['import', { libraryName: 'antd', style: true }], config);
    +   config = rewireLess.withLoaderOptions({
    +     modifyVars: { "@primary-color": "#1DA57A" },
    +   })(config, env);
        return config;
      };

    参考链接:https://ant.design/docs/react/use-with-create-react-app-cn

    使用less

    如果已经配置react-app-rewire-less,则无需再进行此操作

    1.npm install less-loader less --save-dev

    2.修改node_modules/react_script/config下的webpack.config.dev.js 和 webpack.config-prod.js 配置文件

    • test: /.css$/ 改为 /.(css|less)$/
    • test: /.css$/ 的 use 数组配置增加 less-loader
    {
      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
            // https://github.com/facebookincubator/create-react-app/issues/2677
            ident: '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
        }
      ],
    },
  • 相关阅读:
    [洛谷P2463][SDOI2008]Sandy的卡片
    后缀数组
    周记【距gdoi:110天】
    hdu3068最长回文(Manacher算法)
    二分图的一些题目合集
    周记【距gdoi:117天】
    二分图、网络流模版总结
    2014end
    周记【距gdoi:126天】
    2-sat
  • 原文地址:https://www.cnblogs.com/lanshu123/p/10660705.html
Copyright © 2020-2023  润新知