Closed hankaibo closed 4 years ago
Create a sample project on github and reproduce this. I'll look into that and will fix this issue
This is my code. https://github.com/hankaibo/myantdpro/tree/feature/dynamic-theme I know it is a bit big.
In you configurations, you are using variables.less
where as it is vars.less
in you styles directory. This is very important to use the right file containing your theme variables. Also, use src
directory as your styles directory since some styles are in component folder as well.
const options = {
stylesDir: path.join(__dirname, './src'),
antDir: path.join(__dirname, './node_modules/antd'),
varFile: path.join(__dirname, './src/styles/vars.less'),
themeVariables: [
'@primary-color',
'@secondary-color',
'@text-color',
'@text-color-secondary',
'@heading-color',
'@layout-body-background',
'@btn-primary-bg',
'@layout-header-background',
'@border-color-base',
'@white'
],
indexFileName: 'index.html',
outputFilePath: path.join(__dirname, './public/color.less'),
customColorRegexArray: [/^fade\(.*\)$/]
};
Look at this sample color.js and follow this https://github.com/mzohaibqc/antd-theme-generator/blob/master/examples/customize-cra/color.js
You can make some changes to remove light and dark theme changes
const path = require('path');
const fs = require('fs');
const { generateTheme, getLessVars } = require('antd-theme-generator');
const themeVariables = getLessVars(path.join(__dirname, './src/styles/vars.less'))
const options = {
stylesDir: path.join(__dirname, './src'),
antDir: path.join(__dirname, './node_modules/antd'),
varFile: path.join(__dirname, './src/styles/vars.less'),
mainLessFile: path.join(__dirname, './src/styles/main.less'),
themeVariables: Object.keys(themeVariables),
indexFileName: 'index.html',
outputFilePath: path.join(__dirname, './public/color.less'),
}
generateTheme(options).then(less => {
console.log('Theme generated successfully');
})
.catch(error => {
console.log('Error', error);
});
Thanks for your reply.
I don't know why it is. When I execute node coler.js, I received this error: "error evaluating function fade
: Argument cannot be evaluated to a color".
version: 1.2.3.
I don't know what to do, because there is an error it did not generate color.less file. then, I use verison: 1.1.9,it's ok!!!
now, I use it at 1.1.9.
hi, 1.2.4 isn't work. I use your example/create-react-app. Sometimes it is good, But the generated color.less file does not contain my custom file.
@hankaibo I would strongly suggest that use examples/customise-cra
sample code. That is up to date and other examples are bit outdated and I could not spare much time to update all examples.
Sorry, because I used css modules but antd-theme-generator isn't supported. 😭😭😭
@hankaibo Thanks for reply.
So a note for others:
Sorry, because I used css modules but antd-theme-generator isn't supported. 😭😭😭
How did you solve it? I used css modules too
color.js
variables.less
But, the color.less file it generates is a literal not a variable.
I hop it looks like
This is my index.html
Where did I use it wrong?