0
votes

I'm trying to deploy my react-app to netlify. But the tailwindCSS doesn't seem working. I have no error message or anything, so have no clue which way to go. Deployment was successful. I was checking all the answers here and other forums, but nothing solved my problem. Tried different builds, and pushing different settings, but just got a plain HTML page without styles.

My package.json

{
  "name": "benji-portfolio",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@craco/craco": "^6.2.0",
    "@headlessui/react": "^1.4.0",
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-parallax-tilt": "^1.5.54",
    "react-reveal": "^1.2.2",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.1.2"
  },
  "scripts": {
    "start": "craco start",
    "build": "craco build",
    "test": "craco test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "autoprefixer": "^9.8.6",
    "postcss": "^7.0.36",
    "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.2.7"
  }
}

tailwind.config.js

module.exports = {
  purge: [
    '/src/components/About/About.js',
    '/src/components/Contact/Contact.js',
    '/src/components/Navbar/Navbar.js',
    '/src/components/Projects/Projects.js',
    '/src/components/Skills/Skills.js',
    '/public/index.html'
  ],
  darkMode: 'class',
  theme: {
    extend: {
      backgroundImage: (theme) => ({
        'code': "url('/src/components/About/coding-bg-dark.png')",
        'lightcode': "url('/src/components/About/lightcode.png')",
       })
    },
  },
  variants: {
    extend: {
      backgroundImage: ['dark'],
    },
  },
  plugins: [],
}

code structure

Netlify build settings:

Build command: craco build

Publish directory: public/

full github repo HERE

1

1 Answers

0
votes

So after trying all day long. Somehow I made it up and running. I made multiple changes on netlify in the build process, and also changed craco.config.js and tailwind.config.js, until I successed and deployed.

What worked for me, and hopefully some of you will may find it useful is the tailwind.config.js

  1. I changed the module.exports.purge to:
module.exports = {
  purge: [
    "./src/components/**/*.{js,jsx}",
    "./public/index.html",
  ],
...
}
  1. and on the Netlify build settings:

Publish Directory: build