I noticed the answers are quite outdated and not what i needed, Let me help abit.
The main problem i faced was in deploying a svelte/sveltekit app with docker using a dockerfile for production and optimized for production as well.
Using the Dockerfile provided above one would have to update it to look like this:
- for my instance i will make use of
pnpm though, other package managers like yarn and npm can be used as well.
FROM node:jod-alpine AS build
ENV NODE_ENV=production
WORKDIR /app
COPY package.json ./
COPY pnpm-lock.yaml ./
# pnpm must be installed as it doesn't come with the default image
RUN npm i -g pnpm
RUN pnpm i
COPY . ./
RUN pnpm build
# Don't run production as root
FROM gcr.io/distroless/nodejs22-debian12:nonroot AS prod
WORKDIR /app
ENV NODE_ENV=production
COPY --from=installer /app/build ./build
COPY package.json .
EXPOSE 3000
CMD [ "build"]
# ENV HOST is not needed though you can uncomment it if needed
# ENV HOST=0.0.0.0
# EXPOSE 4173
# node is not needed as distroless:nonroot doesn't need node to be specified as user
CMD ["build"]
package.json{scripts}
this is the script section for the package.json
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"test:unit": "vitest run",
"test:ui": "vitest --ui",
"test:integration": "playwright test",
"coverage": "vitest run --coverage",
"lint": "prettier --check . && eslint .",
"format": "prettier --write ."
},
Note: I would advice to only use npm run preview / pnpm preview only in local environment to ensure that the production version used will look the same,
in Production after pnpm build only make use of node build which is optimized for production.