FROM node:22-alpine AS base

RUN apk update && apk add git

COPY package.json ./

RUN npm install
RUN npm install typescript -g

# add folder if needs more
COPY src ./src
COPY public ./public

COPY tsconfig.json ./tsconfig.json
COPY tsconfig.node.json ./tsconfig.node.json
COPY vite.config.ts ./vite.config.ts
COPY tailwind.config.js ./tailwind.config.js
COPY postcss.config.js ./postcss.config.js
COPY eslint.config.mjs ./eslint.config.mjs
COPY .env.production ./.env.production
COPY .prettierrc ./.prettierrc
COPY index.html ./index.html
COPY vhosts.conf ./vhosts.conf

RUN npm run build:production

# FROM node:22-alpine

# Copy node modules and build directory from base image to new image
# COPY --from=base ./node_modules ./node_modules
# COPY --from=base ./package.json ./package.json
# COPY --from=base /dist /dist
# COPY --from=base /src /src
# COPY --from=base /public /public

FROM nginx:alpine
COPY --from=base /dist /usr/share/nginx/html
COPY --from=base /vhosts.conf /etc/nginx/conf.d/default.conf

CMD ["nginx", "-g", "daemon off;"]