Skip to content

Avoiding node_modules in final build #1780

@RicardoGaefke

Description

@RicardoGaefke

❓Question

First of all, thank you very much for your amazing work. I'm using razzle within an ASP.NET Core 5 (Jering.Javascript.NodeJS for ssr) app and it works pretty fine but there is something that I'd like to improve. Using Docker I need to copy node_modules to my final layer which makes it really bigger. This is my dockerfile:

# clones the app
FROM alpine AS gitclone
ARG BRANCH
ARG GIT_CRED

RUN apk update && apk add --no-cache git

RUN mkdir /root/app/
RUN git clone -b ${BRANCH} https://${GIT_CRED}@dev.azure.com/myCompany/myRepo/_git/any ./app

# builds the app
FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine3.12 AS build

RUN apk update && apk add --no-cache nodejs npm

COPY --from=gitclone /app ./app

WORKDIR /app/src/WebSite

RUN dotnet publish -c Release ./WebSite.csproj -r linux-musl-x64 -o ./publish

# runs the app
FROM mcr.microsoft.com/dotnet/aspnet:5.0.4-alpine3.12 as runtime

RUN apk update && apk add --no-cache nodejs npm

RUN export PATH=$PATH:/usr/bin/node:/usr/share/doc/nodejs

ENV ASPNETCORE_URLS=http://+:5000

COPY --from=build /app/src/WebSite/publish ./
COPY --from=build /app/src/WebSite/ClientApp/node_modules ./node_modules
COPY --from=build /app/src/WebSite/ClientApp/build ./ClientApp/build

ENTRYPOINT ["./WebSite"]

The app wasn't working before copying the node_modules and I found this in your docs:

image

Is there a way to build server bundle to avoid copying node_modules?

Thank you very much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions