I'm using webpack 4x and trying to include antd along with babel-plugin-import
. I've updated my webpack config to use:
{
test: /\.less$/,
include: [/[\\/]node_modules[\\/].*antd/],
use: [
'css-loader',
{
loader: 'less-loader',
options: {
modifyVars: { '@primary-color': '#1DA57A' },
javascriptEnabled: true
}
}
]
},
This works, as in it doesn't throw any errors. However, the styles don't seem to be showing up in the actual app. I'm including like this:
import { Button } from 'antd'
class App extends Component {
render() {
return <Button type="primary">Button</Button>
}
}
It's rendering the button just fine, it's just the styles that aren't coming in. Any idea if there's something else that needs to be done so the styles are actually included? Thank you!
Click the "Open in Editor" icon in the first example to open an editor with source code to use out-of-the-box. Now you can import the Alert component into the codesandbox: - import { DatePicker, message } from 'antd'; + import { DatePicker, message, Alert } from 'antd';
Material UI offers a large variety of built-in theme options whereas Ant Design doesn't offer as many of that. Material UI is only suitable for Android apps but Ant Design is compatible with iOS, Android, and web.
If we decide to customize another component in the project, even a widely used one, we will just need to add a file with the wrapper and change the path of that component in the file with re-exports located at src/components/antd/index.
ant-design-pro - Libraries - cdnjs - The #1 free and open source CDN built to make life easier for developers.
you need to import the less file of antd in less :
//main.less
@import "~antd/dist/antd.less";
then import this file in ts/js index:
import './less/main.less';
you can also add the theme config file in main.less
This is the webpack config I use (webpack3):
,{
test: /\.less$/,
use: [{
loader: 'file-loader',
options: {
name: 'theme.css'
}
},{
loader: 'less-loader',
options: { javascriptEnabled: true }// compiles Less to CSS
}]
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With