【问题标题】:Ant design - is there a way to get styles that im actually using?Ant design - 有没有办法获得我实际使用的样式?
【发布时间】:2018-11-27 20:08:39
【问题描述】:

最近安装了ant design https://ant.design/

但是,它不使用样式化组件,只使用旧的基本 css 模块。 .css 文件就像 10k 行。有一种方法可以只使用你需要的这些,但首先你必须安装 babel。

不幸的是,我没有在我的项目中使用 babel,只是打字稿。

https://ant.design/docs/react/introduce - 这里写着我需要 babel 和 babel-import-plugin。但正如我所说,我没有使用它,也不想在我的项目中使用它。

对于那些不想进入外部网站的人:

Use modularized antd#
Use babel-plugin-import (Recommended)

// .babelrc or babel-loader option
{
  "plugins": [
    ["import", { "libraryName": "antd", "libraryDirectory": "es", "style": "css" }] // `style: true` for less
  ]
}

问题:有没有办法使用 typescript 或仅使用 webpack 等来使用模块化 css(仅导入您需要的这些样式)?没有通天塔?

谢谢

【问题讨论】:

    标签: javascript css webpack babeljs antd


    【解决方案1】:

    过去 1 年我一直在使用 Antd 和 react。

    当你尝试使用模块化的 antd 时会出现这个问题,否则这个问题不会存在。

    模块化

    从 'antd/lib/date-picker' 导入 DatePicker; // 对于js

    import 'antd/lib/date-picker/style/css'; // 对于cs

    在非模块化中

    导入'antd/dist/antd.css'; //曾经在 src 文件夹中的 index.js 文件中

    从 'antd' 导入 {DataPicker,Button,Grid}; //你需要的任何组件

    你真的想使用模块化的 antd 吗?

    如果你改变了心情,这里是我的 https://github.com/shreyansRS/react-redux-antd 的 git 存储库

    如果你仍然想使用模块化,我认为在 index.js 中导入 'antd/lib/date-picker/style/css' 应该可以。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-22
      • 1970-01-01
      • 2012-01-01
      • 2020-12-06
      • 2011-10-17
      • 1970-01-01
      • 2021-07-20
      • 2014-08-02
      相关资源
      最近更新 更多