N
Nuxt5mo ago
dmarr

Dockerfile for a nuxt module

Does anyone have an example Dockerfile that would work for a repo that contains a nuxt module at its root? I want to build the module, and then expose the .playground.
2 Replies
kapa.ai
kapa.ai5mo ago
Hi @dmarr. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- If your repository contains a Nuxt module at its root and you want to build the module and expose the .playground (which is a Nuxt app used for development and testing the module), you can use a Dockerfile similar to those used for Nuxt applications, but targeting the .playground directory for build and runtime. The knowledge sources do not provide a ready-made Dockerfile specifically for a Nuxt module repo, but based on the official Nuxt module starter and deployment docs, you should: 1. Build the module (usually handled automatically when running the playground). 2. Build the playground Nuxt app. 3. Expose the playground app for development or testing. Here’s an example Dockerfile adapted from the official Nuxt deployment docs, targeting the .playground directory:
# Build Stage
FROM node:22-alpine AS build
WORKDIR /app

# Enable corepack for pnpm/yarn support if needed
RUN corepack enable

# Copy playground package files
COPY .playground/package.json .playground/pnpm-lock.yaml .playground/

# Install dependencies for the playground
WORKDIR /app/.playground
RUN pnpm install

# Copy the entire module and playground source
WORKDIR /app
COPY . .

# Build the playground Nuxt app (which will also build the module)
WORKDIR /app/.playground
RUN pnpm run build

# Production Stage
FROM node:22-alpine
WORKDIR /app

# Copy only the built output from the playground
COPY --from=build /app/.playground/.output/ ./

ENV PORT 3000
ENV HOST 0.0.0.0

EXPOSE 3000

CMD ["node", "/app/server/index.mjs"]
# Build Stage
FROM node:22-alpine AS build
WORKDIR /app

# Enable corepack for pnpm/yarn support if needed
RUN corepack enable

# Copy playground package files
COPY .playground/package.json .playground/pnpm-lock.yaml .playground/

# Install dependencies for the playground
WORKDIR /app/.playground
RUN pnpm install

# Copy the entire module and playground source
WORKDIR /app
COPY . .

# Build the playground Nuxt app (which will also build the module)
WORKDIR /app/.playground
RUN pnpm run build

# Production Stage
FROM node:22-alpine
WORKDIR /app

# Copy only the built output from the playground
COPY --from=build /app/.playground/.output/ ./

ENV PORT 3000
ENV HOST 0.0.0.0

EXPOSE 3000

CMD ["node", "/app/server/index.mjs"]
Notes: - Adjust for your package manager (pnpm, yarn, or npm) as needed. - This Dockerfile assumes your module and the .playground directory are at the repo root, as is standard with the Nuxt module starter template. - The .playground directory acts as a Nuxt app and is used for development/testing of your module, as described in the Nuxt Module Author Guide. - You may need to tweak the Dockerfile if your module or playground has additional dependencies or custom build steps. For more details on developing and building Nuxt modules with a playground, see the Nuxt Module Author Guide and Deploying with Docker. If you need to run the playground in development mode (hot reload), you can change the CMD to run pnpm run dev instead of node /app/server/index.mjs. If you need a different setup, please provide more details about your module structure. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@139883350096740354> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?