Skip to content

Instantly share code, notes, and snippets.

@jayaregalinada
Last active May 22, 2023 12:49
Show Gist options
  • Save jayaregalinada/9d370dc66ab00d39fd14d08ae0241952 to your computer and use it in GitHub Desktop.
Save jayaregalinada/9d370dc66ab00d39fd14d08ae0241952 to your computer and use it in GitHub Desktop.
Vite in Docker
// The express application
import express from 'express';
import history from 'connect-history-api-fallback';
const app = express();
app.use(history());
// Other middleware
app.use(express.static(path.join(__dirname, 'public')));
// Dockerfile for the Frontend server
// Image: company/frontend-server
FROM node:lts-alpine
ENV PORT 80
WORKDIR /var/www/html
COPY src/package.json .
COPY src/package-lock.json .
COPY src .
RUN npm install -g pm2
RUN npm install --no-dev
EXPOSE $PORT
CMD ["pm2-runtime", "/var/www/html/bin/www.js"]
// Dockerfile for Vite app
FROM node:lts-alpine as build
COPY package.json .
COPY npm-lock.json .
# Install dependencies
RUN npm install
COPY . /tmp
# Build project
RUN npm run build
FROM company/frontend-server:the-version
// Copy generated Vite App and move it in the node frontend-server
COPY --from=build /tmp/dist /var/www/html/public
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment