From f7caaddbeca155c0865c542a5e13eb2193bf7f41 Mon Sep 17 00:00:00 2001 From: Alexander Graf Date: Fri, 4 Nov 2022 23:39:39 +0100 Subject: [PATCH] Speed up asset building when developing --- core/admin/assets/Dockerfile | 20 ++++++++++++------ .../admin/assets/{content => }/assets/app.css | 0 core/admin/assets/{content => }/assets/app.js | 0 .../assets/{content => }/assets/mailu.png | Bin .../assets/{content => }/assets/vendor.js | 0 core/admin/assets/{content => }/package.json | 0 .../assets/{content => }/webpack.config.js | 0 core/admin/run_dev.sh | 13 +++++------- 8 files changed, 18 insertions(+), 15 deletions(-) rename core/admin/assets/{content => }/assets/app.css (100%) rename core/admin/assets/{content => }/assets/app.js (100%) rename core/admin/assets/{content => }/assets/mailu.png (100%) rename core/admin/assets/{content => }/assets/vendor.js (100%) rename core/admin/assets/{content => }/package.json (100%) rename core/admin/assets/{content => }/webpack.config.js (100%) diff --git a/core/admin/assets/Dockerfile b/core/admin/assets/Dockerfile index c8556f47..613aa6c0 100644 --- a/core/admin/assets/Dockerfile +++ b/core/admin/assets/Dockerfile @@ -4,13 +4,19 @@ FROM node:16-alpine3.16 WORKDIR /work -COPY content/ ./ +COPY package.json ./ +COPY webpack.config.js ./ RUN set -euxo pipefail \ - && npm config set update-notifier false \ - && npm install --no-audit --no-fund \ - && sed -i 's/#007bff/#55a5d9/' node_modules/admin-lte/build/scss/_bootstrap-variables.scss \ - && for l in ca da de:de-DE en:en-GB es:es-ES eu fr:fr-FR he hu is it:it-IT ja nb_NO:no-NB nl:nl-NL pl pt:pt-PT ru sv:sv-SE zh; do \ + ; npm config set update-notifier false \ + ; npm install --no-audit --no-fund \ + ; sed -i 's/#007bff/#55a5d9/' node_modules/admin-lte/build/scss/_bootstrap-variables.scss \ + ; mkdir assets \ + ; for l in ca da de:de-DE en:en-GB es:es-ES eu fr:fr-FR he hu is it:it-IT ja nb_NO:no-NB nl:nl-NL pl pt:pt-PT ru sv:sv-SE zh; do \ cp node_modules/datatables.net-plugins/i18n/${l#*:}.json assets/${l%:*}.json; \ - done \ - && node_modules/.bin/webpack-cli --color + done + +COPY assets/ ./assets/ + +RUN set -euxo pipefail \ + ; node_modules/.bin/webpack-cli --color diff --git a/core/admin/assets/content/assets/app.css b/core/admin/assets/assets/app.css similarity index 100% rename from core/admin/assets/content/assets/app.css rename to core/admin/assets/assets/app.css diff --git a/core/admin/assets/content/assets/app.js b/core/admin/assets/assets/app.js similarity index 100% rename from core/admin/assets/content/assets/app.js rename to core/admin/assets/assets/app.js diff --git a/core/admin/assets/content/assets/mailu.png b/core/admin/assets/assets/mailu.png similarity index 100% rename from core/admin/assets/content/assets/mailu.png rename to core/admin/assets/assets/mailu.png diff --git a/core/admin/assets/content/assets/vendor.js b/core/admin/assets/assets/vendor.js similarity index 100% rename from core/admin/assets/content/assets/vendor.js rename to core/admin/assets/assets/vendor.js diff --git a/core/admin/assets/content/package.json b/core/admin/assets/package.json similarity index 100% rename from core/admin/assets/content/package.json rename to core/admin/assets/package.json diff --git a/core/admin/assets/content/webpack.config.js b/core/admin/assets/webpack.config.js similarity index 100% rename from core/admin/assets/content/webpack.config.js rename to core/admin/assets/webpack.config.js diff --git a/core/admin/run_dev.sh b/core/admin/run_dev.sh index a2e32912..a682252c 100755 --- a/core/admin/run_dev.sh +++ b/core/admin/run_dev.sh @@ -47,14 +47,11 @@ cp -r "${base}"/libs . sed -E '/^#/d;s:^FROM system$:FROM system AS base:' "${base}/Dockerfile" >Dockerfile # assets -cp -r "${assets}/content" . +cp "${assets}/package.json" . +cp -r "${assets}/assets/" . +awk '/new compress/{f=1}!f{print}/}),/{f=0}' <"${assets}/webpack.config.js" >webpack.config.js sed -E '/^#/d;s:^(FROM [^ ]+$):\1 AS assets:' "${assets}/Dockerfile" >>Dockerfile -cat >>Dockerfile <>Dockerfile @@ -107,8 +104,8 @@ for vol in audit.py start.py mailu/ migrations/; do volumes+=( --volume "${admin}/${vol}:/app/${vol}" ) done -for file in "${assets}/content/assets"/*; do - [[ "${file}" == */vendor.js ]] && continue +for file in "${assets}/assets"/*; do + [[ ! -f "${file}" || "${file}" == */vendor.js ]] && continue volumes+=( --volume "${file}:/app/static/${file/*\//}" ) done