react-vite

Complete deployment guide for react-vite on NStrim

Overview

React Vite is a modern React setup using Vite as the build tool. It offers lightning-fast development with Hot Module Replacement (HMR), optimized production builds, and a modern development experience with React 19.

Before You Start
Make sure you have your dashboard open - you'll need the Git credentials displayed there. This template includes Tailwind CSS 4, Redux Toolkit, React Router, and Framer Motion.

Quick Start

1

Create Repository from Template

On your dashboard, go to the Tools & Deployment tab. Click the "New Repository" button, select the React Vite template from the dropdown, enter a repository name and subdomain, then click "Create Repository".

2

Clone Your Repository

git clone https://<git-server>/<username>/<repo-name>.git
cd <repo-name>
3

Install Dependencies

npm install
4

Start Development Server

npm run dev

Open http://localhost:4200 in your browser.

5

Build & Push

npm run build
git add .
git commit -m "Initial setup"
git push origin main
Every push to Git automatically deploys your application. Check your Module Work URL on the dashboard to see your live site.

Local Development with Docker

If you don't have Node.js installed locally, you can use Docker to run React commands. The project includes a Dockerfile for production builds with nginx.

What is Docker?
Docker creates isolated "containers" with all the software you need (Node.js, npm) without installing them on your computer. Think of it like a lightweight virtual machine.

Prerequisites

Install Docker Desktop for your operating system (Windows, Mac, or Linux).

Running Commands with Docker

# Run npm install
docker run --rm -v $(pwd):/app -w /app node:lts-alpine npm install

# Run development server (accessible at localhost:4200)
docker run --rm -v $(pwd):/app -w /app -p 4200:4200 node:lts-alpine npm run dev

# Build for production
docker run --rm -v $(pwd):/app -w /app node:lts-alpine npm run build
Note
Docker is optional for local development. The NStrim platform handles deployment automatically - you only need Docker if you want to run commands locally without Node.js installed.

Project Structure

Understanding where files are located:

├── src/
│   ├── App.jsx               # Root component
│   ├── App.css               # App-specific styles
│   ├── main.jsx              # Application entry point
│   ├── index.css             # Global styles (Tailwind)
│   └── assets/               # Static assets (images, etc.)
├── public/                   # Public static files
├── index.html                # HTML entry point
├── vite.config.js            # Vite configuration
├── package.json              # Dependencies and scripts
├── nginx.conf                # Nginx config for production
└── Dockerfile                # Docker build configuration
        

Common Tasks

Creating a Component

Create .jsx files in src/:

// src/components/Button.jsx
export default function Button({ label, onClick }) {
  return (
    <button
      className="bg-blue-500 text-white px-4 py-2 rounded"
      onClick={onClick}
    >
      {label}
    </button>
  );
}

Using React Router

React Router is pre-configured. Add routes in your App:

import { BrowserRouter, Routes, Route } from 'react-router-dom';
import Home from './pages/Home';
import About from './pages/About';

function App() {
  return (
    <BrowserRouter>
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="/about" element={<About />} />
      </Routes>
    </BrowserRouter>
  );
}

Using Redux Toolkit

Redux Toolkit is pre-installed for state management:

import { createSlice } from '@reduxjs/toolkit';

const counterSlice = createSlice({
  name: 'counter',
  initialState: { value: 0 },
  reducers: {
    increment: (state) => { state.value += 1 },
    decrement: (state) => { state.value -= 1 },
  },
});

export const { increment, decrement } = counterSlice.actions;
export default counterSlice.reducer;

Using Tailwind CSS

Tailwind CSS 4 is pre-configured. Use classes directly in your JSX:

<div className="bg-blue-500 text-white p-4 rounded-lg">
  Hello Tailwind!
</div>

Useful Commands

npm run dev Start development server (port 4200)
npm run build Build for production
npm run preview Preview production build locally
npm run lint Check code style and errors

Troubleshooting

npm install fails with permission errors

Cause: Permission issues with npm cache or node_modules.

Solution: Delete node_modules folder and package-lock.json, then run npm install again.

Port 4200 already in use

Cause: Another process is using port 4200.

Solution: Use a different port: npm run dev -- --port 3000 or stop the other process.

Module not found errors

Cause: Dependencies not installed or corrupted.

Solution: Run npm install to install all dependencies.

Changes not reflecting in browser

Cause: Browser cache or HMR not working.

Solution: Hard refresh (Ctrl+Shift+R or Cmd+Shift+R) or restart the dev server.

Build fails after deployment

Cause: Build errors or missing dependencies.

Solution: Run npm run build locally first to check for errors before pushing.

Deployment Workflow

Every time you push code to Git, your application is automatically built and deployed:

Code Change git push npm run build Deploy to nginx Live!

Your deployed application URL follows this format:

https://<your-subdomain>-<repo-name>.<session-domain>

Example: https://student01-module-a.demo.nstrim.app

For more information, visit the official React Documentation and Vite Documentation.