Background image with CRA #2725
-
I'm trying to migrate from NEXT.JS to CRA. Everything seems to work fine excepted that I cannot use the I also tried to import it with fullpath, it is also doesn't work.
I think the real issue is I didn't really integrate tailwind into the build of CRA.
Right now, I have to do work around by create another css file and manually write down all the background Image thingy. i.e.
With this, I can still use other tailwind BG classes. Is there a better way to setup tailwind with CRA, so that BG image could work fine? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hey @natsathorn! I have actually been working on Tailwind CSS integration guides that we'll release in a couple of weeks - one of them being with CRA 👍 To have a more integrated setup, you can use something called Here's the setup below. Hope it helps! 👍 Not sure if it will sort out your image problem, but it will improve the "integration" of Tailwind as part of the CRA build. Using Tailwind CSS with Create React AppCreating your projectStart by creating a new Create React App project if you don't have one set up already: npx create-react-app my-project Setting up Tailwind CSSInstall Tailwind, Autoprefixer and CRACO using npm install tailwindcss autoprefixer@^9 @craco/craco Next, let's generate default npx tailwindcss init Then, let's create a // craco.config.js
module.exports = {
style: {
postcss: {
plugins: [require("tailwindcss"), require("autoprefixer")],
},
},
}; Now, let's replace the content of @tailwind base;
@tailwind components;
@tailwind utilities; That's it! Tailwind CSS is now available throughout our entire application 🎉 |
Beta Was this translation helpful? Give feedback.
-
Hey, If you're trying to reference an image from your CSS in Create React App, it's going to try and reference it from the compiled CSS file. Instead of having it in your Have a try and see how you go! 🤞 |
Beta Was this translation helpful? Give feedback.
-
This works for us:
|
Beta Was this translation helpful? Give feedback.
Hey,
If you're trying to reference an image from your CSS in Create React App, it's going to try and reference it from the compiled CSS file.
Instead of having it in your
src
directory, I think you need to put that image in yourpublic
folder: https://create-react-app.dev/docs/using-the-public-folder/.Have a try and see how you go! 🤞