【发布时间】:2021-05-03 18:04:04
【问题描述】:
我是 Gatsby 的新手,我正在使用带有 postcss 的 tailwind css。我在tailwind.config.js 的主题对象中定义的一些颜色配置在开发环境中有效,但在生产环境中无效。我已经尝试清理缓存并删除公用文件夹并重新构建它。那并没有解决问题。我在tailwind.config.js 中的主题对象是这样的:
theme: {
colors: {
transparent: 'transparent',
current: 'currentColor',
primary: {
DEFAULT: '#4F9C3A',
900: '#25441c',
},
secondary: {
0: '#ff9563',
DEFAULT: '#E66437',
9: '#ae3409',
},
footer: {
light: '#e66437',
DEFAULT: '#383e42',
dark: '#26292c',
},
neutral: {
0: '#ffffff',
DEFAULT: '#ffffff',
1: '#fafafa',
9: '#000000',
},
accent: {
1: '#388ac5',
DEFAULT: '#293842',
},
brown: {
DEFAULT: '#C9AC75',
2: '#44261c',
},
black: '#000000',
}
}
更新:我已经能够查明问题的根源。我正在使用 gatsby-transformer-json 从 json 文件中获取要应用的类名。我有类似以下代码段来设置在开发环境中工作但在生产环境中工作的背景颜色。
<div className={`bg-${color}>
The development build shows proper background color for this segment but production build does not.
</div>
【问题讨论】:
-
可能不是颜色设置的问题,而是清除问题。也许你没有配置它或其他东西。需要查看你的整个 tailwind.config.js 以及你的工作文件在哪里(我不熟悉 Gatsby)
-
您是否尝试过将这些样式移至全局样式?
-
你上一个sn-p有错别字,应该是:
<div className={`bg-${color}`}>。
标签: gatsby tailwind-css