This GatsbyJS/antd plugin page (https://github.com/bskimball/gatsby-plugin-antd/issues/2) makes it seem that there is a way to edit ant.design (antd) themes when using GatsbyJS. The code that is provided is
plugins: [
{
resolve: 'gatsby-plugin-antd',
options: {
style: true
}
}
]
But there is no additional information. Where would one make changes to things like the theme primary color (as described: https://ant.design/docs/react/customize-theme). The ant.design page (https://ant.design/docs/react/customize-theme) says to make the primary color change by doing the following:
"theme": {
"primary-color": "#1DA57A",
},
It is not clear in what file such a variable would be set in GatbsyJS.
GitHub repo with an example: https://github.com/uciska/gatsby-less-v2. To get Antd working changes must be made to three Gatsby files.
Example gastby-config.js:
module.exports = {
siteMetadata: {
title: 'My site'
},
plugins: [
{
resolve: `gatsby-plugin-less`,
options: {
javascriptEnabled: true,
modifyVars: {
'primary-color': '#da3043',
'font-family': 'Arial',
'layout-body-background': '#66ff79'
}
}
}
]
}
Example gastby-node.js:
exports.onCreateBabelConfig = ({ actions }) => {
actions.setBabelPlugin({
name: 'babel-plugin-import',
options: {
libraryName: 'antd',
style: true
}
})
}
Example package.json:
{
"name": "gatsby-starter-hello-world",
"description": "Gatsby hello world starter",
"license": "MIT",
"scripts": {
"develop": "gatsby develop",
"build": "gatsby build",
"serve": "gatsby serve"
},
"dependencies": {
"antd": "^3.6.4",
"babel-plugin-import": "^1.8.0",
"gatsby": "next",
"gatsby-plugin-less": "next",
"less": "^3.0.4",
"less-loader": "^4.1.0",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"react-apollo": "^2.1.11"
}
}
I have tried all of the above answers which were written a few years back, but it didn't work. After researching for a couple of hours, finally, I was able to modify antd
default vars with gatsby
. Here is the solution:
gatsby-config.js
[
...
...
{
resolve: "gatsby-plugin-antd",
options: {
style: true,
},
},
{
resolve: "gatsby-plugin-less",
options: {
lessOptions: {
modifyVars: { //direct child node of lessOptions
"primary-color": "#C53333", //your preferred color
},
javascriptEnabled: true, //direct child node of lessOptions
},
},
},
]
less
and less-loader
are NOT required to modify default antd
vars.
package.json
"dependencies": {
"antd": "^4.12.2",
"gatsby-plugin-antd": "^2.2.0",
"gatsby-plugin-less": "^4.7.0",
}
side note: Find all the ant-design default vars here
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