question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Antd styles not working

See original GitHub issue

I am trying to install antd into this boilerplate. The components are working fine but the styles are not applied. I tried following their guide installing yarn add babel-plugin-import and then yarn then i edited my .babelrc:

"plugins": [
  "add-module-exports",
  [
    "import",
    {
      "libraryName": "antd",
      "libraryDirectory": "es",
      "style": "css"
    }
  ]
],

but still, the styles do not apply. If I inspect the html i can see the classes applied to the button but no styles related to those classes. I tried importing the styles in every way and the only way i could make it work was adding this in the head of app.html, just below the title: <script type="style/css" src="../node_modules/antd/dist/antd.css"> but it was only working in dev, when i package my application it obviously does not work. I couldn’t find any information on how to make styles work, any idea? To reproduce the situation just clone this repo, and try make antd work. If you succeed doing that please share your work

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
gcfabricommented, Nov 27, 2018

Example here

What I supposed to do? I installed antd package and import on app.global.css: @import '~antd/dist/antd.css';

I made some changes on Home component to use a simple Button from antd and then run script package-win.

The css seems to work but the fonts are broken. See this image

3reactions
wujian-nerccommented, Sep 19, 2018

I solved by modifying webpack.config.render.dev/prod.js

{
  test: /^((?!\.global).)*\.css$/,
  exclude: /node_modules/,
  use: [
    {
      loader: 'style-loader'
    },
    {
      loader: 'css-loader',
      options: {
        modules: true,
        sourceMap: true,
        importLoaders: 1,
        localIdentName: '[name]__[local]__[hash:base64:5]'
      }
    }
  ]
},
{
  test: /\.css$/,
  include: /node_modules/,
  use: [
    {
      loader: 'style-loader'
    },
    {
      loader: 'css-loader'
    }
  ]
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Ant-Design CSS not loading properly - Stack Overflow
P.S - If you are using a single component for instance lets say Input, then import only that part. import 'antd/es/input/style/index.css';.
Read more >
antd styles do not load in Create react app · Issue #313 - GitHub
Expected behavior is that styles should load from antd. However this is not the case and plain html elements show up.
Read more >
Getting Started - Ant Design
Ant Design React is dedicated to providing a good development experience for programmers. Before starting, it is recommended to learn React and ES2015...
Read more >
antd css not working - Code Examples & Solutions For This ...
import "antd/dist/antd.css"; ... Technical Problem Cluster First Answered On August 8, 2022 Popularity 6/10 Helpfulness 5/10 ... ant design css not working.
Read more >
[Solved]-Ant-Design CSS not loading properly-Reactjs
[Solved]-Ant-Design CSS not loading properly-Reactjs ... import 'antd/dist/antd.css', use this import to your root component. ... Add @import '~antd/dist/antd.css';.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found