Skip to content

Commit

Permalink
Run Django + Webpack dev server concurrently without Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
browniebroke committed Mar 25, 2022
1 parent d566190 commit 121d4d3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -27,7 +27,7 @@ production-ready Django projects quickly.
- Registration via [django-allauth](https://github.com/pennersr/django-allauth)
- Comes with custom user model ready to go
- Optional basic ASGI setup for Websockets
- Optional custom static build using Gulp and livereload
- Optional custom static build using Gulp or Webpack
- Send emails via [Anymail](https://github.com/anymail/django-anymail) (using [Mailgun](http://www.mailgun.com/) by default or Amazon SES if AWS is selected cloud provider, but switchable)
- Media storage using Amazon S3 or Google Cloud Storage
- Docker support using [docker-compose](https://github.com/docker/compose) for development and production (using [Traefik](https://traefik.io/) with [LetsEncrypt](https://letsencrypt.org/) support)
Expand Down
57 changes: 38 additions & 19 deletions hooks/post_gen_project.py
Expand Up @@ -136,13 +136,14 @@ def update_package_json(remove_dev_deps=None, remove_keys=None, scripts=None):
fd.write("\n")


def handle_js_runner(choice):
def handle_js_runner(choice, use_docker, use_async):
if choice == "Gulp":
update_package_json(
remove_dev_deps=[
"@babel/core",
"@babel/preset-env",
"babel-loader",
"concurrently",
"css-loader",
"mini-css-extract-plugin",
"postcss-loader",
Expand All @@ -162,23 +163,37 @@ def handle_js_runner(choice):
)
remove_webpack_files()
elif choice == "Webpack":
update_package_json(
remove_dev_deps=[
"browser-sync",
"cssnano",
"gulp",
"gulp-imagemin",
"gulp-plumber",
"gulp-postcss",
"gulp-rename",
"gulp-sass",
"gulp-uglify-es",
],
scripts={
"dev": "webpack serve --config webpack/dev.config.js ",
"build": "webpack --config webpack/prod.config.js",
},
)
scripts = {
"dev": "webpack serve --config webpack/dev.config.js",
"build": "webpack --config webpack/prod.config.js",
}
remove_dev_deps = [
"browser-sync",
"cssnano",
"gulp",
"gulp-imagemin",
"gulp-plumber",
"gulp-postcss",
"gulp-rename",
"gulp-sass",
"gulp-uglify-es",
]
if not use_docker:
dev_django_cmd = (
"gunicorn config.asgi -k uvicorn.workers.UvicornWorker --reload"
if use_async
else "python manage.py runserver_plus"
)
scripts.update(
{
"dev": "concurrently npm:dev:*",
"dev:webpack": "webpack serve --config webpack/dev.config.js",
"dev:django": dev_django_cmd,
}
)
else:
remove_dev_deps.append("concurrently")
update_package_json(remove_dev_deps=remove_dev_deps, scripts=scripts)
remove_gulp_files()


Expand Down Expand Up @@ -469,7 +484,11 @@ def main():
if "{{ cookiecutter.use_docker }}".lower() == "y":
remove_node_dockerfile()
else:
handle_js_runner("{{ cookiecutter.frontend_pipeline }}")
handle_js_runner(
"{{ cookiecutter.frontend_pipeline }}",
use_docker=("{{ cookiecutter.use_docker }}".lower() == "y"),
use_async=("{{ cookiecutter.use_async }}".lower() == "y"),
)

if "{{ cookiecutter.cloud_provider }}" == "None":
print(
Expand Down
1 change: 1 addition & 0 deletions {{cookiecutter.project_slug}}/package.json
Expand Up @@ -11,6 +11,7 @@
"browser-sync": "^2.27.7",
"css-loader": "^6.5.1",
"gulp-concat": "^2.6.1",
"concurrently": "^7.0.0",
"cssnano": "^5.0.11",
"gulp": "^4.0.2",
"gulp-imagemin": "^7.1.0",
Expand Down

0 comments on commit 121d4d3

Please sign in to comment.