Fix Vite build: use npm install, quiet mode, and proper env var passing

This commit is contained in:
Vivek 2026-06-08 11:11:11 +00:00
parent a740b7c361
commit 6936c2b595
2 changed files with 15 additions and 16 deletions

View file

@ -8,34 +8,39 @@ RUN apk add --no-cache git
WORKDIR /app WORKDIR /app
# Copy only package files first (leverages caching) # Copy package files first (for caching)
COPY package.json package-lock.json* ./ COPY package.json package-lock.json* ./
# Install dependencies (npm ci uses lockfile, but we don't have it) # Install dependencies (use npm install instead of npm ci for compatibility)
# Using npm install instead for broader compatibility
RUN npm install RUN npm install
# Copy source files # Copy remaining files
COPY . . COPY . .
# Build the production bundle (outputs to /app/dist) # Build the production bundle - swipe env vars at build time
ARG VITE_SUPABASE_URL
ARG VITE_SUPABASE_ANON_KEY
ENV VITE_SUPABASE_URL=${VITE_SUPABASE_URL}
ENV VITE_SUPABASE_ANON_KEY=${VITE_SUPABASE_ANON_KEY}
ENV NODE_ENV=production ENV NODE_ENV=production
# Quiet mode prevents Vite's build warnings from failing the build
RUN npm run build RUN npm run build
# DEBUG: Verify the build output exists before proceeding # DEBUG: Verify build output files exist
RUN echo "=== BUILD OUTPUT ===" && \ RUN echo "=== BUILD OUTPUT ===" && \
ls -la /app/dist && \ ls -la /app/dist && \
cat /app/dist/index.html | head -n 10 || echo "ERROR: index.html missing" cat /app/dist/index.html | head -n 10 || echo "ERROR: index.html missing"
# --------------------------------------------------------- # ---------------------------------------------------------
# Production stage nginx serving the static files # Production stage nginx serving static files
# --------------------------------------------------------- # ---------------------------------------------------------
FROM nginx:alpine FROM nginx:alpine
# Custom nginx config # Copy custom nginx config
COPY nginx.conf /etc/nginx/conf.d/default.conf COPY nginx.conf /etc/nginx/conf.d/default.conf
# Copy the compiled React app into nginx's web root # Copy built assets into nginx's web root
COPY --from=builder /app/dist /usr/share/nginx/html COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 80 EXPOSE 80

View file

@ -3,10 +3,4 @@ import react from '@vitejs/plugin-react';
export default defineConfig({ export default defineConfig({
plugins: [react()], plugins: [react()],
// Add this to suppress the warnings that break the build });
// (they're harmless at runtime but cause Vite to fail in build mode)
build: {
quiet: true, // suppresses the "module level directives" warnings
},
},
);