A modern e-commerce platform built using Vite, Node.js, and Docker, featuring server-side rendering, real-time updates, and a seamless shopping experience.
- Features
- Prerequisites
- Local Development
- Docker Deployment
- Project Structure
- Docker Support
- Contributing
- Contributing
- Contributing
- [Contributing](#Common Errors and Resolutions)
- π Complete E-commerce Solution β A robust online shopping application with essential features.
- β‘ Powered by Vite β Enables rapid development with hot reloading.
- π³ Optimized with Docker β Uses Distroless for enhanced security and efficiency.
- π± Easily Deployable β Runs on port 3000, making deployment straightforward.
Ensure you have the following installed:
# Required
Node.js >= 18.x
npm >= 9.x
Docker >= 20.x# Create a local directory
mkdir -p ~/hackathon
# Navigate to the project directory
cd ~/hackathon
# Clone the repository
git clone https://github.com/your-username/online_shop.git
# Navigate to the project directory
cd online_shop
# Install dependencies
npm install
# Run development server
npm run devThe project uses a multi-stage build with Node.js 18 Alpine for building and a Distroless Node.js 18 image for production.
# Stage 1: Build using Node.js with Alpine
FROM node:18-alpine as builder
# Set working directory
WORKDIR /app
# Copy package.json
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of the application files
COPY . .
# Build the project
RUN npm run build
# Stage 2: Use a lightweight Distroless image for the final image
FROM gcr.io/distroless/nodejs18 AS production
# Set working directory
WORKDIR /app
# Copy only necessary files from builder stage
COPY --from=builder /app /app
# Expose port 3000 for the app
EXPOSE 3000
# Start the application
CMD ["node_modules/.bin/vite", "--host", "0.0.0.0", "--port", "3000"]Create a docker-compose.yml file:
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
volumes:
- .:/app
- /app/node_modules
environment:
- NODE_ENV=production
command: ["node_modules/.bin/vite", "--host", "0.0.0.0", "--port", "3000"]To prevent unnecessary files from being copied into the image, add the following to .dockerignore:
node_modules
.git
.env
# Build the Docker image
docker build -t online-shop-frontend:latest .
# Check docker Images
docker images
# Run container
docker run -d \
--name online_shop \
-p 3000:3000 \
-e NODE_ENV=production \
--restart unless-stopped \
online-shop-frontend:latestdocker-compose up -d
docker-compose up -donline-shop-frontend/
βββ src/
β βββ components/ # React components
β βββ context/ # Context API for state management
β βββ data/ # Static or API-related data
β βββ hooks/ # Custom React hooks
β βββ pages/ # Application pages
β βββ services/ # API service functions
β βββ utilities/ # Utility functions
β βββ App.jsx # Root component
β βββ bootstrap-overrides.scss # Bootstrap custom styles
β βββ index.css # Global CSS styles
β βββ main.jsx # Entry point for React
βββ .gitignore # Git ignore file
βββ CONTRIBUTING.md # Contribution guidelines
βββ LICENSE # License file
βββ README.md # Documentation file
βββ ROADMAP.md # Roadmap file
βββ eslint.config.js # ESLint configuration
βββ index.html # Main HTML file
βββ package-lock.json # npm lock file
βββ package.json # Project metadata & dependencies
βββ vite.config.js # Vite configuration file
| Command | Description |
|---|---|
docker build |
Build the image |
docker-compose up |
Start all services |
docker-compose down |
Stop all services |
docker logs |
View container logs |
# Build image
docker build -t online-shop-frontend:latest .
# Tag image
docker tag online-shop-frontend:latest your-dockerhub-username/online_shop:v1.0
# Push to Docker Hub
docker push your-dockerhub-username/online_shop:v1.0- Fork the repository (GitHub Link)
- Create your feature branch (
git checkout -b Hackathon) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin Hackathon) - Open a Pull Request
This project is licensed under the MIT License.
Shrinivas Joshi - LinkedIn
Project Link: GitHub
Dockerizing React Application Built with Vite - A Simple Guide https://thedkpatel.medium.com/dockerizing-react-application-built-with-vite-a-simple-guide-4c41eb09defa
Multi-stage Dockerfile for NestJS https://medium.com/@madhuwanthapriyashanbandara/multi-stage-dockerfile-for-nestjs-d91c7a66937b
You installed esbuild for another platform than the one you're currently using. This won't work: Resolved using this StackOverflow answer
"vite is not recognized ..." on "npm run dev": Resolved using this StackOverflow answer
node:internal/modules/cjs/loader:942 throw err; ^ Error: Cannot find module 'express' Require stack: Updated the package with serve dependency and used the correct CMD command.