Reduzierung der Docker -Bildgröße von Next.js in einem TurborepoJavaScript

Javascript-Forum
Anonymous
 Reduzierung der Docker -Bildgröße von Next.js in einem Turborepo

Post by Anonymous »

Ich habe einen Turborepo mit einer nächsten.

Code: Select all

eslint-config

[*]

Code: Select all

typescript-config
[*]

Code: Select all

ui
Alle drei Pakete werden in der nächsten Anwendung verwendet. Bin ich unbeabsichtigt unnötige Dateien oder folge ich nicht den richtigen Turborepo -Workflow, der die Bildgröße aufblasen könnte?

Code: Select all

FROM node:20-alpine AS base

# Prune project
FROM base AS prune
WORKDIR /app
RUN npm install -g turbo
COPY . .
RUN turbo prune @project/admin-frontend --docker

# Install dependencies
FROM base AS installer
WORKDIR /app
COPY --from=prune /app/out/json/ .
RUN npm install

# Install production dependencies
FROM base AS installer-production
WORKDIR /app
COPY --from=prune /app/out/json .
RUN npm install --only=production

# Build the project
FROM base AS builder
WORKDIR /app
COPY --from=installer /app/node_modules /app/node_modules
COPY --from=prune /app/out/full/ .
RUN npx turbo build --filter=@project/admin-frontend

# Final image
FROM base AS runner
WORKDIR /app
COPY --from=installer-production /app/node_modules /app/node_modules
COPY --from=builder  /app/apps/admin-frontend/package.json /app/apps/admin-frontend/
COPY --from=builder  /app/apps/admin-frontend/.next /app/apps/admin-frontend/.next

WORKDIR /app/apps/admin-frontend

CMD ["npm", "run", "start"]
< /code>
Dies ist das Paket.json der nächsten.js Anwendung: < /p>
{
"name": "@project/admin-frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "dotenv -e .env -- next dev --turbopack",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@project/ui": "*",
"next": "15.2.3",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
"@project/eslint-config": "*",
"@project/typescript-config": "*",
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"dotenv-cli": "^8.0.0",
"eslint": "^9",
"eslint-config-next": "15.2.3",
"tailwindcss": "^4",
"typescript": "^5"
}
}

Wenn ich DU in/App/Apps/Admin-Frontend im Container ausführe, erhalte ich die folgende Ausgabe.

Code: Select all

12  ./.next/diagnostics
12  ./.next/static/css
96  ./.next/static/media
8   ./.next/static/chunks/app/_not-found
20  ./.next/static/chunks/app
12  ./.next/static/chunks/pages
796 ./.next/static/chunks
12  ./.next/static/_eCz52W9GGEyf7Z-bojwC
920 ./.next/static
12  ./.next/types/app
28  ./.next/types
8   ./.next/cache/eslint
4   ./.next/cache/swc/plugins/v7_linux_aarch64_8.0.0
8   ./.next/cache/swc/plugins
12  ./.next/cache/swc
12  ./.next/cache/webpack/edge-server-production
22208   ./.next/cache/webpack/client-production
15416   ./.next/cache/webpack/server-production
37640   ./.next/cache/webpack
37668   ./.next/cache
348 ./.next/server/chunks
20  ./.next/server/app/_not-found
72  ./.next/server/app/favicon.ico
212 ./.next/server/app
48  ./.next/server/pages
660 ./.next/server
39536   ./.next
39544   .

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post