compress static assets
This commit is contained in:
parent
59026d0fb6
commit
81988555d2
|
@ -1,17 +1,16 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from os import environ
|
from os import environ
|
||||||
|
|
||||||
# All that comes from the environment needs to be defined here
|
|
||||||
_DEBUG = bool(environ.get('E11SYNC_DEBUG', False))
|
_DEBUG = bool(environ.get('E11SYNC_DEBUG', False))
|
||||||
|
_COMPRESS_OFFLINE = bool(environ.get('E11SYNC_COMPRESS_OFFLINE', False))
|
||||||
_STATIC_ROOT = environ.get('E11SYNC_STATIC_ROOT', '/tmp/e11sync-static')
|
_STATIC_ROOT = environ.get('E11SYNC_STATIC_ROOT', '/tmp/e11sync-static')
|
||||||
_GEOIP_PATH = environ.get("GEOIP_PATH")
|
_GEOIP_PATH = environ.get('GEOIP_PATH')
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
## No more side effects after this place
|
## No more side effects after this place
|
||||||
########################################
|
|
||||||
|
|
||||||
SECRET_KEY = 'django-insecure-$e2!=equ(efm0e%f9&t+xjtz0)$*$@pw%rnjdqcl8f@5o5hw!l'
|
SECRET_KEY = 'django-insecure-$e2!=equ(efm0e%f9&t+xjtz0)$*$@pw%rnjdqcl8f@5o5hw!l'
|
||||||
|
|
||||||
|
@ -105,9 +104,27 @@ STATICFILES_FINDERS = [
|
||||||
|
|
||||||
STATIC_ROOT = _STATIC_ROOT
|
STATIC_ROOT = _STATIC_ROOT
|
||||||
|
|
||||||
|
# At the time of testing:
|
||||||
|
# main-full.css: 34K
|
||||||
|
# main-mini.css: 49K
|
||||||
|
# main-full.css.br: 5.0K
|
||||||
|
# main-mini.css.br: 7.1K
|
||||||
|
#
|
||||||
|
# Minifying those files will necessitate sourcemaps, which
|
||||||
|
# is not currently possible due to
|
||||||
|
# https://github.com/django-compressor/django-compressor/issues/438
|
||||||
|
# Since the savings with minification are not that huge, let's keep
|
||||||
|
# it a bir larger, but much simpler.
|
||||||
|
COMPRESS_ENABLED = True
|
||||||
|
|
||||||
|
COMPRESS_OFFLINE = _COMPRESS_OFFLINE
|
||||||
|
|
||||||
|
COMPRESS_FILTERS = {
|
||||||
|
'css': [],
|
||||||
|
'js': [],
|
||||||
|
}
|
||||||
|
|
||||||
COMPRESS_PRECOMPILERS = (
|
COMPRESS_PRECOMPILERS = (
|
||||||
# TODO: --style=compressed + source maps
|
|
||||||
# https://github.com/django-compressor/django-compressor/issues/438
|
|
||||||
('text/x-scss', 'sass {infile} {outfile}'),
|
('text/x-scss', 'sass {infile} {outfile}'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
14
flake.nix
14
flake.nix
|
@ -63,11 +63,15 @@
|
||||||
];
|
];
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
mkdir -p $out/static
|
mkdir -p $out/static
|
||||||
env \
|
export E11SYNC_STATIC_ROOT=$out/static
|
||||||
E11SYNC_STATIC_ROOT=$out/static \
|
export E11SYNC_DEBUG=
|
||||||
E11SYNC_DEBUG= \
|
export E11SYNC_COMPRESS_OFFLINE=1
|
||||||
${pkgs.python3}/bin/python3 \
|
${pkgs.python3}/bin/python3 ${self}/app/manage.py collectstatic
|
||||||
${self}/app/manage.py collectstatic
|
${pkgs.python3}/bin/python3 ${self}/app/manage.py compress
|
||||||
|
|
||||||
|
${pkgs.findutils}/bin/find $out/static/CACHE -name '*.css' | \
|
||||||
|
${pkgs.findutils}/bin/xargs -P8 -I{} sh -c \
|
||||||
|
"${pkgs.zopfli}/bin/zopfli {} && ${pkgs.brotli}/bin/brotli {}"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
devShells.default = pkgs.mkShellNoCC {
|
devShells.default = pkgs.mkShellNoCC {
|
||||||
|
|
Loading…
Reference in New Issue