Skip to content

hellosimplerick/tailwind-dev

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

This is a super basic template for react js/tailwind v3. What's below is the output from Google's AI studio if you want to make this yourself.

Important: This was done and designed for use within codespaces.

A Verified, Manual-Fix Guide for React + Tailwind in Codespaces

This guide documents the precise, manual process required to create a stable React and Tailwind CSS v3 environment in GitHub Codespaces. It is a record of a successfully debugged session, created to bypass critical issues with npm installing pre-release software and npx command failures within the Codespace environment.

This process works because it makes no assumptions. It forces the correct dependency versions and manually creates configuration files to bypass broken tooling.


Step 1: The Foundation - A Clean Container

First, we create a stable, lightweight environment.

  1. Start with a new, empty GitHub repository.

  2. In that repository, create the file .devcontainer/devcontainer.json and add the following content. This ensures you get a clean Node.js environment without the bloat that can cause storage errors.

    {
      "name": "Node.js-Vite-React-Stable",
      "image": "mcr.microsoft.com/devcontainers/javascript-node:1-20-bullseye",
      "customizations": {
        "vscode": {
          "extensions": [ "bradlc.vscode-tailwindcss", "esbenp.prettier-vscode" ]
        }
      }
    }
  3. Commit the file and launch the Codespace from your repository's < > Code menu.

Step 2: Scaffold the Project and Force Correct Dependencies

We will create the Vite project files and then immediately fix the package.json before installing anything. This is the key to preventing all downstream errors.

  1. Once the Codespace is running, a terminal will be open. Create the base React project files in the current directory:

    npm create vite@latest . -- --template react
  2. DO NOT RUN npm install YET. Open the package.json file that was just created.

  3. Delete the entire "devDependencies": { ... } block and replace it with this verified block that forces the stable Tailwind v3 and its compatible dependencies:

    "devDependencies": {
      "@types/react": "^18.3.3",
      "@types/react-dom": "^18.3.0",
      "@vitejs/plugin-react": "^4.3.1",
      "autoprefixer": "^10.4.19",
      "eslint": "^8.57.0",
      "eslint-plugin-react": "^7.34.4",
      "eslint-plugin-react-hooks": "^4.6.2",
      "eslint-plugin-react-refresh": "^0.4.8",
      "postcss": "^8.4.39",
      "tailwindcss": "^3.4.6",
      "vite": "^5.3.4"
    }
  4. Save the package.json file. Now that the correct versions are specified, run the install command. This will download the packages we just defined.

    npm install

Step 3: Manually Create and Populate Configuration Files

The npx tailwindcss init -p command repeatedly failed. We will bypass it completely by creating and writing the files ourselves.

  1. In the terminal, use the touch command to create the two empty configuration files:
    touch tailwind.config.js
    touch postcss.config.js
  2. Open the newly created tailwind.config.js file from the explorer. Paste the following configuration into it:
    /** @type {import('tailwindcss').Config} */
    export default {
      content: [
        "./index.html",
        "./src/**/*.{js,ts,jsx,tsx}",
      ],
      theme: {
        extend: {},
      },
      plugins: [],
    }
  3. Open the newly created postcss.config.js file. Paste the following configuration into it. This is the correct format for Tailwind v3.
    export default {
      plugins: {
        tailwindcss: {},
        autoprefixer: {},
      },
    }

Step 4: Integrate CSS into the React Application

Tell the application to load the CSS file containing the Tailwind styles.

  1. Open src/index.css. Delete all of its contents and replace them with the three Tailwind directives:
    @tailwind base;
    @tailwind components;
    @tailwind utilities;
  2. Open src/main.jsx. Add the import statement for index.css at the top of the file to ensure the styles are loaded by Vite.
    import React from 'react';
    import ReactDOM from 'react-dom/client';
    import App from './App.jsx';
    import './index.css'; // This line loads the styles
    
    ReactDOM.createRoot(document.getElementById('root')).render(
      <React.StrictMode>
        <App />
      </React.StrictMode>,
    );

Step 5: Final Verification

The setup is now complete and correct. Run the development server and use a test component to verify the result.

  1. In the terminal, run the server:
    npm run dev
  2. When the notification appears, click Open in Browser. You will see the default, unstyled Vite page.
  3. Now, open src/App.jsx. Delete all of its content and replace it with this test code:
    function App() {
      return (
        <div className="bg-slate-900 min-h-screen flex items-center justify-center font-sans">
          <div className="max-w-md mx-auto bg-slate-800 rounded-xl shadow-2xl overflow-hidden p-8 space-y-4">
            <div className="text-center">
              <h1 className="text-4xl font-bold text-indigo-400">
                It Works.
              </h1>
              <p className="mt-2 text-lg text-slate-300">
                The correct Tailwind v3 styles are now applied.
              </p>
            </div>
            <div className="pt-4">
              <button className="w-full bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-3 px-4 rounded-lg">
                Success
              </button>
            </div>
          </div>
        </div>
      )
    }
    
    export default App
  4. Save the App.jsx file. The browser tab should hot-reload and display a fully styled card. This confirms the entire process was successful.

About

A Template to get reactJS/Tailwind up for testing UI/UX

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published