Merge pull request #31 from H4CK3R-01/generate_minimized_files

Minimize js and css files in docker build
This commit is contained in:
Florian Kaiser 2021-06-16 10:16:44 +02:00 committed by GitHub
commit bef6e0bc96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -5,11 +5,16 @@ WORKDIR /usr/src/app
COPY package*.json ./ COPY package*.json ./
RUN npm install RUN npm install
RUN npm install uglifycss -g
RUN npm install uglify-js -g
COPY Webservice Webservice COPY Webservice Webservice
COPY public public COPY public public
COPY data data COPY data data
COPY minimize.sh minimize.sh
RUN chmod +x minimize.sh
RUN ./minimize.sh
RUN sed -i "s/DATE_TO_BE_REPLACED/$(date +%s)/" public/index.html RUN sed -i "s/DATE_TO_BE_REPLACED/$(date +%s)/" public/index.html
RUN sed -i "s/COMMIT_TO_BE_REPLACED/GitHub: $(git ls-remote https://github.com/H4CK3R-01/Projektmanagement-Game refs/heads/main | awk '{print $1;}' | cut -c1-7)/" public/index.html RUN sed -i "s/COMMIT_TO_BE_REPLACED/GitHub: $(git ls-remote https://github.com/H4CK3R-01/Projektmanagement-Game refs/heads/main | awk '{print $1;}' | cut -c1-7)/" public/index.html
RUN sed -i "s/COMMIT_LINK_TO_BE_REPLACED/https\:\/\/github.com\/H4CK3R-01\/Projektmanagement-Game\/commit\/$(git ls-remote https://github.com/H4CK3R-01/Projektmanagement-Game refs/heads/main | awk '{print $1;}')/" public/index.html RUN sed -i "s/COMMIT_LINK_TO_BE_REPLACED/https\:\/\/github.com\/H4CK3R-01\/Projektmanagement-Game\/commit\/$(git ls-remote https://github.com/H4CK3R-01/Projektmanagement-Game refs/heads/main | awk '{print $1;}')/" public/index.html

20
minimize.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/sh
which uglifycss
#minification of JS files
cd public/js || exit
for f in *.js; do
case "$f" in
*"min.js") ;;
*) uglifyjs "$f" > "${f%.js}".min.js && sed -i "s/$f/${f%.js}.min.js/" ../index.html
esac
done
#minification of CSS files
cd ../css || exit
for f in *.css; do
case "$f" in
*"min.css") ;;
*) uglifycss --output "${f%.css}".min.css "$f" && sed -i "s/$f/${f%.css}.min.css/" ../index.html
esac
done