'Ant Design & Webpack not loading css
I've got a React project using Antd and webpack as I wanted to use css modules, however unfortunately this is impacting Antd and I'm way out of my depth to understand how to resolve this.
In my webpack config, I have the following loader:
{
test: /\.css$/,
use: [
require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: {
importLoaders: 1,
modules: true,
localIdentName: "[name]__[local]___[hash:base64:5]"
},
},
{
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',
}),
],
},
},
],
},
I can confirm that this is working for my own styled elements, but Antd component s are unstyled.
In my App.js, I am importing the antd.css file, however when bundled, it applies the css modules to the antd.css. This obviously causes a problem as the Antd components haven't had their class names changed.
Can anyone guide me through how to resolve this please?
Solution 1:[1]
you can solve this by adding the @import '~antd/dist/antd.css'; to your css file. However I am also looking for a solution by making the changes in webpack.config
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | suren |
