reactjs - 如何在 styled-components 的 GlobalStyles 中引入 Ant Design 的 css 样式?

标签 reactjs antd styled-components

如何在样式组件中导入 antd.css?而不是 App.css

@import '~antd/dist/antd.css';

整个目的是,我希望 styled-components 中的 GlobalStyles 默认具有所有 Ant Design 样式。

当我使用 AntD 中的元素时,它将包含所有默认类。

最佳答案

You shouldn't .

NOTE: At this time we recommend not using @import inside of createGlobalStyle. We're working on better behavior for this functionality but it just doesn't really work at the moment and it's better if you just embed these imports in your HTML index file, etc.

虽然你可以尝试:

import { createGlobalStyle, css } from 'styled-components';

const antdCss = css`
  ${import('antd/dist/antd.css')}
`;

const GlobalStyle = createGlobalStyle`
  ${antdCss}
`;

export default GlobalStyle;

Edit busy-williamson-xmodn

关于reactjs - 如何在 styled-components 的 GlobalStyles 中引入 Ant Design 的 css 样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59848920/

相关文章:

javascript - 嵌套渲染不影响 DOM

reactjs - 使用带有react-emotion的嵌套伪CSS选择器

css - Ant design v4 中如何动态切换主题?

javascript - 样式化组件 : Global Colors Style Sheet

twitter-bootstrap - Webpack 导入 bootstrap .js 和 .css

javascript - 继承倒置 HOC 无法将类作为函数调用

javascript - Antd 表单初始值在状态更改后不更新

javascript - react组件中如何使用antd divider分隔屏幕的两侧?

reactjs - 如何在样式组件中注册多个字体粗细?

html - 相邻同级未获取 CSS 变量值