mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-07-30 17:59:48 +03:00
Add webpack as an option
Adds webpack as a js_taskrunner option to cookiecutter-json. Will clone @hzdg/cookiecutter-webpack --pydanny-django branch into the project using cookiecutter's api in post_hooks. The static webpack project will be placed into the <project_slug>/static/<project_slug>/ directory. The webpack configs are placed in the ./config/ directory. The cookiecutter-webpack project includes react / redux / karma configurations that are brought into the project.
This commit is contained in:
parent
d771f12a55
commit
f036ae431a
|
@ -122,6 +122,7 @@ Listed in alphabetical order.
|
||||||
Travis McNeill `@Travistock`_ @tavistock_esq
|
Travis McNeill `@Travistock`_ @tavistock_esq
|
||||||
Vitaly Babiy
|
Vitaly Babiy
|
||||||
Vivian Guillen `@viviangb`_
|
Vivian Guillen `@viviangb`_
|
||||||
|
Will Farley `@goldhand`_ @g01dhand
|
||||||
Yaroslav Halchenko
|
Yaroslav Halchenko
|
||||||
========================== ============================ ==============
|
========================== ============================ ==============
|
||||||
|
|
||||||
|
@ -156,6 +157,7 @@ Listed in alphabetical order.
|
||||||
.. _@eyadsibai: https://github.com/eyadsibai
|
.. _@eyadsibai: https://github.com/eyadsibai
|
||||||
.. _@garry-cairns: https://github.com/garry-cairns
|
.. _@garry-cairns: https://github.com/garry-cairns
|
||||||
.. _@garrypolley: https://github.com/garrypolley
|
.. _@garrypolley: https://github.com/garrypolley
|
||||||
|
.. _@goldhand: https://github.com/goldhand
|
||||||
.. _@hackebrot: https://github.com/hackebrot
|
.. _@hackebrot: https://github.com/hackebrot
|
||||||
.. _@hairychris: https://github.com/hairychris
|
.. _@hairychris: https://github.com/hairychris
|
||||||
.. _@hjwp: https://github.com/hjwp
|
.. _@hjwp: https://github.com/hjwp
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
"use_docker": "y",
|
"use_docker": "y",
|
||||||
"use_heroku": "n",
|
"use_heroku": "n",
|
||||||
"use_compressor": "n",
|
"use_compressor": "n",
|
||||||
"js_task_runner": ["Gulp", "Grunt", "None"],
|
"js_task_runner": ["Gulp", "Grunt", "Webpack", "None"],
|
||||||
"use_lets_encrypt": "n",
|
"use_lets_encrypt": "n",
|
||||||
"open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"]
|
"open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"]
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
|
from cookiecutter.main import cookiecutter
|
||||||
|
|
||||||
# Get the root project directory
|
# Get the root project directory
|
||||||
PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)
|
PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)
|
||||||
|
@ -161,6 +162,30 @@ def remove_packageJSON_file():
|
||||||
PROJECT_DIRECTORY, filename
|
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():
|
def remove_certbot_files():
|
||||||
"""
|
"""
|
||||||
Removes files needed for certbot if it isn't going to be used
|
Removes files needed for certbot if it isn't going to be used
|
||||||
|
@ -212,6 +237,11 @@ if '{{ cookiecutter.js_task_runner}}'.lower() == 'gulp':
|
||||||
remove_grunt_files()
|
remove_grunt_files()
|
||||||
elif '{{ cookiecutter.js_task_runner}}'.lower() == 'grunt':
|
elif '{{ cookiecutter.js_task_runner}}'.lower() == 'grunt':
|
||||||
remove_gulp_files()
|
remove_gulp_files()
|
||||||
|
elif '{{ cookiecutter.js_task_runner }}'.lower() == 'webpack':
|
||||||
|
remove_gulp_files()
|
||||||
|
remove_grunt_files()
|
||||||
|
remove_packageJSON_file()
|
||||||
|
add_webpack()
|
||||||
else:
|
else:
|
||||||
remove_gulp_files()
|
remove_gulp_files()
|
||||||
remove_grunt_files()
|
remove_grunt_files()
|
||||||
|
|
|
@ -47,6 +47,16 @@ Running tests with py.test
|
||||||
::
|
::
|
||||||
|
|
||||||
$ py.test
|
$ py.test
|
||||||
|
{% if cookiecutter.js_task_runner == 'Webpack' %}
|
||||||
|
|
||||||
|
Running javascript tests with karma
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
$ npm test
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
Live reloading and Sass CSS compilation
|
Live reloading and Sass CSS compilation
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
@ -243,5 +243,18 @@ STATICFILES_FINDERS += ("compressor.finders.CompressorFinder", )
|
||||||
|
|
||||||
# Location of root django.contrib.admin URL, use {% raw %}{% url 'admin:index' %}{% endraw %}
|
# Location of root django.contrib.admin URL, use {% raw %}{% url 'admin:index' %}{% endraw %}
|
||||||
ADMIN_URL = r'^admin/'
|
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
|
# Your common stuff: Below this line define 3rd party library settings
|
||||||
|
|
|
@ -303,5 +303,19 @@ LOGGING = {
|
||||||
{% endif %}
|
{% endif %}
|
||||||
# Custom Admin URL, use {% raw %}{% url 'admin:index' %}{% endraw %}
|
# Custom Admin URL, use {% raw %}{% url 'admin:index' %}{% endraw %}
|
||||||
ADMIN_URL = env('DJANGO_ADMIN_URL')
|
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
|
# Your production stuff: Below this line define 3rd party library settings
|
||||||
|
|
|
@ -58,4 +58,9 @@ celery==3.1.23
|
||||||
django_compressor==2.0
|
django_compressor==2.0
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if cookiecutter.js_task_runner == 'Webpack' -%}
|
||||||
|
# Webpack
|
||||||
|
django-webpack-loader==0.3.0
|
||||||
|
{%- endif %}
|
||||||
|
|
||||||
# Your custom requirements go here
|
# Your custom requirements go here
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{% raw %}{% load staticfiles i18n {% endraw %}{% if cookiecutter.use_compressor == "y" %}compress{% endif %}{% raw %}%}<!DOCTYPE html>
|
{% 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 %}<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
|
@ -76,7 +77,9 @@
|
||||||
<div class="alert {% if message.tags %}alert-{{ message.tags }}{% endif %}">{{ message }}</div>
|
<div class="alert {% if message.tags %}alert-{{ message.tags }}{% endif %}">{{ message }}</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endraw %}{% if cookiecutter.js_task_runner == 'Webpack' %}{% raw %}
|
||||||
|
<div id="main"></div>
|
||||||
|
{% endraw %}{% endif %}{% raw %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<p>Use this document as a way to quick start any new project.</p>
|
<p>Use this document as a way to quick start any new project.</p>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
@ -99,12 +102,17 @@
|
||||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js" integrity="sha384-vZ2WRJMwsjRMW/8U7i6PWi6AlO1L79snBrmgiDpgIWJ82z8eA5lenwvxbMV1PAh7" crossorigin="anonymous"></script>
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js" integrity="sha384-vZ2WRJMwsjRMW/8U7i6PWi6AlO1L79snBrmgiDpgIWJ82z8eA5lenwvxbMV1PAh7" crossorigin="anonymous"></script>
|
||||||
|
|
||||||
<!-- Your stuff: Third-party javascript libraries go here -->
|
<!-- Your stuff: Third-party javascript libraries go here -->
|
||||||
|
{% endraw %}{% if cookiecutter.js_task_runner == 'Webpack' %}{% raw %}
|
||||||
|
<!-- Webpack bundles -->
|
||||||
|
{% render_bundle 'vendor' %}
|
||||||
|
{% render_bundle 'common' %}
|
||||||
|
{% render_bundle 'main' %}
|
||||||
|
{% endraw %}{% else %}{% raw %}
|
||||||
<!-- place project specific Javascript in this file -->
|
<!-- place project specific Javascript in this file -->
|
||||||
{% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% compress js %}{% endraw %}{% endif %}{% raw %}
|
{% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% compress js %}{% endraw %}{% endif %}{% raw %}
|
||||||
<script src="{% static 'js/project.js' %}"></script>
|
<script src="{% static 'js/project.js' %}"></script>
|
||||||
{% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% endcompress %}{% endraw %}{% endif %}{% raw %}
|
{% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% endcompress %}{% endraw %}{% endif %}{% raw %}
|
||||||
|
{% endraw %}{% endif %}{% raw %}
|
||||||
{% endblock javascript %}
|
{% endblock javascript %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user