When working on my CRA project, I encountered an issue with background images not appearing in the production environment. Despite adding custom background images by modifying the theme.backgroundImage
section of my tailwind.config.js file, the images only show up locally and not in production. It seems that the CSS class (e.g., bg-1989
) is being applied but is not actually adding a background-image
property.
// tailwindcss.config.js
module.exports = {
theme: {
extend: {
backgroundImage: theme => ({
'1984':
"linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('./images/Homepage_1984.jpg')",
'1989':
"linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('./images/Homepage_1989.jpg')",
'1997':
"linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('./images/Homepage_1997.jpg')",
'2003':
"linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('./images/Homepage_2003.jpg')",
'2014':
"linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('./images/Homepage_2014.jpg')",
'2019':
"linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('./images/Homepage_2019.jpg')",
'2020':
"linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('./images/Homepage_2020.jpg')"
})
}
}
};
I am utilizing these images as shown below:
<div className={`hero-image bg-${year.id}`}>
<div className="small-headline text-white absolute w-full scene-name">
<Container className="grid__container">
<Row className="grid__row">
<Col lg={2} />
<Col lg={6}>{year.title}</Col>
<Col lg={4}>{year.id}</Col>
</Row>
</Container>
</div>
</div>
// package.json
{
"name": "on-borrowed-time",
"version": "0.1.0",
"private": true,
"dependencies": {
"express": "^4.17.1",
"node-sass": "^4.14.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-grid-system": "^7.1.1",
"react-html-parser": "^2.0.2",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.1",
"web-vitals": "^0.2.4"
},
.
.
.
"devDependencies": {
"autoprefixer": "^9.8.6",
"postcss": "^7.0.36",
"prettier": "^1.19.1",
"sass": "^1.30.0",
"tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.2.4"
}
}