zoukankan      html  css  js  c++  java
  • 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
        }
      ],
    },
  • 相关阅读:
    C#面向对象编程
    WPF Storyboard的启动
    WPF中的窗体Show()和ShowDialog()区别。
    四元数
    小学生四则运算
    小学生四则运算
    javascript ===与==的区别
    a标签的href与onclick中使用js的区别
    10步让你成为更优秀的程序员
    检查SQL Server被哪个进程占用,且杀进程。
  • 原文地址:https://www.cnblogs.com/lanshu123/p/10660705.html
Copyright © 2011-2022 走看看