diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 28768fa439..442e49c50f 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -122,6 +122,7 @@ Listed in alphabetical order. Travis McNeill `@Travistock`_ @tavistock_esq Vitaly Babiy Vivian Guillen `@viviangb`_ + Will Farley `@goldhand`_ @g01dhand Yaroslav Halchenko ========================== ============================ ============== @@ -156,6 +157,7 @@ Listed in alphabetical order. .. _@eyadsibai: https://github.com/eyadsibai .. _@garry-cairns: https://github.com/garry-cairns .. _@garrypolley: https://github.com/garrypolley +.. _@goldhand: https://github.com/goldhand .. _@hackebrot: https://github.com/hackebrot .. _@hairychris: https://github.com/hairychris .. _@hjwp: https://github.com/hjwp diff --git a/cookiecutter.json b/cookiecutter.json index d3017023e2..55ce2cfd65 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -18,7 +18,7 @@ "use_docker": "y", "use_heroku": "n", "use_compressor": "n", - "js_task_runner": ["Gulp", "Grunt", "None"], + "js_task_runner": ["Gulp", "Grunt", "Webpack", "None"], "use_lets_encrypt": "n", "open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"] } diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index d83d922872..2268da2299 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -16,6 +16,7 @@ import os import random import shutil +from cookiecutter.main import cookiecutter # Get the root project directory PROJECT_DIRECTORY = os.path.realpath(os.path.curdir) @@ -161,6 +162,30 @@ def remove_packageJSON_file(): PROJECT_DIRECTORY, filename )) + +def add_webpack(): + """ + Adds webpack configuration using cookiecutter to install hzdg/cookiecutter-webpack + """ + cookiecutter( + 'git@github.com:hzdg/cookiecutter-webpack.git', + replay=False, overwrite_if_exists=True, output_dir='../', + checkout='pydanny-django', no_input=True, extra_context={ + 'project_name': '{{ cookiecutter.project_name }}', + 'repo_name': '{{ cookiecutter.project_slug }}', + 'repo_owner': '', + 'project_dir': '{{ cookiecutter.project_slug }}', + 'static_root': '{{ cookiecutter.project_slug }}/static/{{ cookiecutter.project_slug }}', + 'production_output_path': '{{ cookiecutter.project_slug }}/static/{{ cookiecutter.project_slug }}/dist/', + 'author_name': '{{ cookiecutter.author_name }}', + 'description': '{{ cookiecutter.description }}', + 'version': '{{ cookiecutter.version }}', + 'existing_project': 'y', + 'css_extension': 'sass', + 'use_ejs': 'n', + 'open_source_license': '{{ cookiecutter.open_source_license }}' + }) + def remove_certbot_files(): """ Removes files needed for certbot if it isn't going to be used @@ -212,6 +237,11 @@ def remove_certbot_files(): remove_grunt_files() elif '{{ cookiecutter.js_task_runner}}'.lower() == 'grunt': remove_gulp_files() +elif '{{ cookiecutter.js_task_runner }}'.lower() == 'webpack': + remove_gulp_files() + remove_grunt_files() + remove_packageJSON_file() + add_webpack() else: remove_gulp_files() remove_grunt_files() diff --git a/{{cookiecutter.project_slug}}/README.rst b/{{cookiecutter.project_slug}}/README.rst index 55a520c54e..308c4086a4 100644 --- a/{{cookiecutter.project_slug}}/README.rst +++ b/{{cookiecutter.project_slug}}/README.rst @@ -47,6 +47,16 @@ Running tests with py.test :: $ py.test +{% if cookiecutter.js_task_runner == 'Webpack' %} + +Running javascript tests with karma +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +:: + + $ npm test +{% endif %} + Live reloading and Sass CSS compilation ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/{{cookiecutter.project_slug}}/config/settings/common.py b/{{cookiecutter.project_slug}}/config/settings/common.py index cedf3c7f10..898e60ef99 100644 --- a/{{cookiecutter.project_slug}}/config/settings/common.py +++ b/{{cookiecutter.project_slug}}/config/settings/common.py @@ -243,5 +243,18 @@ # Location of root django.contrib.admin URL, use {% raw %}{% url 'admin:index' %}{% endraw %} ADMIN_URL = r'^admin/' +{% if cookiecutter.js_task_runner == 'Webpack' %} +# WEBPACK +# ------------------------------------------------------------------------------ +INSTALLED_APPS += ('webpack_loader',) +# Webpack Local Stats file +STATS_FILE = ROOT_DIR('webpack-stats.json') +# Webpack config +WEBPACK_LOADER = { + 'DEFAULT': { + 'STATS_FILE': STATS_FILE + } +} +{% endif %} # Your common stuff: Below this line define 3rd party library settings diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index fdd4050485..e4a919128e 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -303,5 +303,19 @@ {% endif %} # Custom Admin URL, use {% raw %}{% url 'admin:index' %}{% endraw %} ADMIN_URL = env('DJANGO_ADMIN_URL') +{% if cookiecutter.js_task_runner == 'Webpack' %} + +# WEBPACK +# ------------------------------------------------------------------------------ +# Webpack Production Stats file +STATS_FILE = ROOT_DIR('webpack-stats-production.json') +# Webpack config +WEBPACK_LOADER = { + 'DEFAULT': { + 'BUNDLE_DIR_NAME': '{{ cookiecutter.project_slug }}/static/{{ cookiecutter.project_slug }}/dist/', + 'STATS_FILE': STATS_FILE + } +} +{% endif %} # Your production stuff: Below this line define 3rd party library settings diff --git a/{{cookiecutter.project_slug}}/requirements/base.txt b/{{cookiecutter.project_slug}}/requirements/base.txt index 9c1d4d9f1e..4b4b142092 100644 --- a/{{cookiecutter.project_slug}}/requirements/base.txt +++ b/{{cookiecutter.project_slug}}/requirements/base.txt @@ -58,4 +58,9 @@ celery==3.1.23 django_compressor==2.0 {% endif %} +{% if cookiecutter.js_task_runner == 'Webpack' -%} +# Webpack +django-webpack-loader==0.3.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 b491855cfe..19340ac4b0 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html @@ -1,4 +1,5 @@ -{% raw %}{% load staticfiles i18n {% endraw %}{% if cookiecutter.use_compressor == "y" %}compress{% endif %}{% raw %}%} +{% raw %}{% load staticfiles i18n {% endraw %}{% if cookiecutter.use_compressor == "y" %}compress {% endif %}{% raw %}%} +{% endraw %}{% if cookiecutter.js_task_runner == 'Webpack' -%}{% raw %}{% load render_bundle from webpack_loader %}{% endraw %}{%- endif %}{% raw %} @@ -76,7 +77,9 @@
{{ message }}
{% endfor %} {% endif %} - +{% endraw %}{% if cookiecutter.js_task_runner == 'Webpack' %}{% raw %} +
+{% endraw %}{% endif %}{% raw %} {% block content %}

Use this document as a way to quick start any new project.

{% endblock content %} @@ -99,12 +102,17 @@ - +{% endraw %}{% if cookiecutter.js_task_runner == 'Webpack' %}{% raw %} + + {% render_bundle 'vendor' %} + {% render_bundle 'common' %} + {% render_bundle 'main' %} +{% endraw %}{% else %}{% raw %} {% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% compress js %}{% endraw %}{% endif %}{% raw %} {% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% endcompress %}{% endraw %}{% endif %}{% raw %} - +{% endraw %}{% endif %}{% raw %} {% endblock javascript %}