From ec62aa03ba7ca854b2a65ce58701e41ff6a93c13 Mon Sep 17 00:00:00 2001 From: Jose Henrique Date: Fri, 10 Jul 2026 19:09:32 -0300 Subject: [PATCH] trying to optmize --- Dockerfile | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9dc0ec3..0a67a54 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,16 +4,21 @@ WORKDIR /src COPY . /src -# Install terser to minify JS files -RUN npm install -g terser -RUN if [ -d "js" ]; then find js -type f -name "*.js" -exec sh -c 'for f; do terser "$f" -c -m -o "$f"; done' sh {} +; fi +# Build a production-only copy so the source tree remains useful for local +# development and the final image contains no unminified source assets. +RUN npm install --global --no-audit --no-fund --no-update-notifier \ + terser@5.49.0 clean-css-cli@5.6.3 html-minifier-terser@7.2.0 \ + && mkdir -p /src/dist/css /src/dist/js \ + && find css -type f -name '*.css' -exec sh -c 'for file do target="/src/dist/$file"; mkdir -p "$(dirname "$target")"; cleancss -O 1 --output "$target" "$file"; done' sh {} + \ + && find js -type f -name '*.js' -exec sh -c 'for file do target="/src/dist/$file"; mkdir -p "$(dirname "$target")"; terser "$file" --compress --mangle --comments false --output "$target"; done' sh {} + \ + && find . -maxdepth 1 -type f -name '*.html' -exec sh -c 'for file do target="/src/dist/$file"; html-minifier-terser --collapse-whitespace --remove-comments --remove-redundant-attributes --use-short-doctype --minify-css=true --minify-js=true "$file" --output "$target"; done' sh {} + \ + && cp -R assets /src/dist/assets FROM nginx:alpine-slim AS final COPY nginx.conf /etc/nginx/nginx.conf -COPY . /usr/share/nginx/html -COPY --from=build /src/js /usr/share/nginx/html/js +COPY --from=build /src/dist /usr/share/nginx/html EXPOSE 80 -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file +CMD ["nginx", "-g", "daemon off;"] -- 2.49.1