diff --git a/cookiecutter.json b/cookiecutter.json index 9b21f3cd..d3017023 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -17,6 +17,7 @@ "use_python2": "n", "use_docker": "y", "use_heroku": "n", + "use_compressor": "n", "js_task_runner": ["Gulp", "Grunt", "None"], "use_lets_encrypt": "n", "open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"] diff --git a/{{cookiecutter.project_slug}}/config/settings/common.py b/{{cookiecutter.project_slug}}/config/settings/common.py index 3e11ee43..3da3cef7 100644 --- a/{{cookiecutter.project_slug}}/config/settings/common.py +++ b/{{cookiecutter.project_slug}}/config/settings/common.py @@ -233,6 +233,13 @@ BROKER_URL = env('CELERY_BROKER_URL', default='django://') ########## END CELERY {% endif %} +# django-compressor +# ------------------------------------------------------------------------------ +{% if cookiecutter.use_compressor == 'y'-%} +INSTALLED_APPS += ("compressor", ) +STATICFILES_FINDERS += ("compressor.finders.CompressorFinder", ) +{%- endif %} + # Location of root django.contrib.admin URL, use {% raw %}{% url 'admin:index' %}{% endraw %} ADMIN_URL = r'^admin/' diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index e2bac6c9..fdd40504 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -140,14 +140,19 @@ STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' {% else %} STATIC_URL = 'https://s3.amazonaws.com/%s/static/' % AWS_STORAGE_BUCKET_NAME STATICFILES_STORAGE = 'config.settings.production.StaticRootS3BotoStorage' - # See: https://github.com/antonagestam/collectfast # For Django 1.7+, 'collectfast' should come before # 'django.contrib.staticfiles' AWS_PRELOAD_METADATA = True INSTALLED_APPS = ('collectfast', ) + INSTALLED_APPS {%- endif %} - +{% if cookiecutter.use_compressor == 'y'-%} +# COMPRESSOR +# ------------------------------------------------------------------------------ +COMPRESS_STORAGE = 'storages.backends.s3boto.S3BotoStorage' +COMPRESS_URL = STATIC_URL +COMPRESS_ENABLED = env.bool('COMPRESS_ENABLED', default=True) +{%- endif %} # EMAIL # ------------------------------------------------------------------------------ DEFAULT_FROM_EMAIL = env('DJANGO_DEFAULT_FROM_EMAIL', diff --git a/{{cookiecutter.project_slug}}/env.example b/{{cookiecutter.project_slug}}/env.example index 3138a9df..95a6a1d9 100644 --- a/{{cookiecutter.project_slug}}/env.example +++ b/{{cookiecutter.project_slug}}/env.example @@ -31,3 +31,6 @@ DJANGO_OPBEAT_ORGANIZATION_ID DJANGO_OPBEAT_APP_ID DJANGO_OPBEAT_SECRET_TOKEN {% endif %} +{% if cookiecutter.use_compressor == 'y' -%} +COMPRESS_ENABLED= +{% endif %} \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/requirements/base.txt b/{{cookiecutter.project_slug}}/requirements/base.txt index 5450a098..9c1d4d9f 100644 --- a/{{cookiecutter.project_slug}}/requirements/base.txt +++ b/{{cookiecutter.project_slug}}/requirements/base.txt @@ -54,4 +54,8 @@ redis>=2.10.0 celery==3.1.23 {% endif %} +{% if cookiecutter.use_compressor == "y" %} +django_compressor==2.0 +{% endif %} + # Your custom requirements go here diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html index bc9dc552..b491855c 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html @@ -1,4 +1,4 @@ -{% raw %}{% load staticfiles i18n %} +{% raw %}{% load staticfiles i18n {% endraw %}{% if cookiecutter.use_compressor == "y" %}compress{% endif %}{% raw %}%}
@@ -18,9 +18,10 @@ - + {% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% compress css %}{% endraw %}{% endif %}{% raw %} + {% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% endcompress %}{% endraw %}{% endif %}{% raw %} {% endblock %} @@ -100,7 +101,10 @@ + {% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% compress js %}{% endraw %}{% endif %}{% raw %} + {% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% endcompress %}{% endraw %}{% endif %}{% raw %} + {% endblock javascript %}