2024-09-17 21:42:05 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
from django.contrib.staticfiles.management.commands.runserver import (
|
|
|
|
Command as Runserver,
|
|
|
|
)
|
|
|
|
from django.utils.autoreload import DJANGO_AUTORELOAD_ENV
|
|
|
|
|
2024-10-09 14:28:54 +00:00
|
|
|
from staticfiles.processors import OpenApi, Webpack
|
2024-09-17 21:42:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Command(Runserver):
|
|
|
|
"""Light wrapper around the statics runserver that integrates webpack auto bundling"""
|
|
|
|
|
|
|
|
def run(self, **options):
|
2024-10-09 14:28:54 +00:00
|
|
|
# OpenApi generation needs to be before webpack
|
|
|
|
OpenApi.compile()
|
2024-09-17 21:42:05 +00:00
|
|
|
# Only run webpack server when debug is enabled
|
|
|
|
# Also protects from re-launching the server if django reloads it
|
|
|
|
if os.environ.get(DJANGO_AUTORELOAD_ENV) is None and settings.DEBUG:
|
|
|
|
with Webpack.runserver():
|
|
|
|
super().run(**options)
|
|
|
|
return
|
|
|
|
super().run(**options)
|