Migrating from browser-sync to django-browser-reload
Starting with version 3.1.0, Django-Tailwind is dropping support for Node.JS-based browser-sync and switching to Django-based django-browser-reload as the primary solution for seamless page and asset updates during development.
If you generated Tailwind CSS before 3.1.0, I strongly suggest you to upgrade your project.
If you don’t want to upgrade and are happy with
browser-sync, make sure that you haveTAILWIND_DEV_MODE=DEBUGset in yoursettings.pyfile.
Please follow the following migration steps.
Upgrade Django-Tailwind to its latest version:
pip install django-tailwind --upgrade
Add
django_browser_reloadtoINSTALLED_APPSinsettings.py:INSTALLED_APPS = [ # other Django apps 'tailwind', 'theme', 'django_browser_reload' ]
Staying in
settings.py, add the middleware:MIDDLEWARE = [ # ... "django_browser_reload.middleware.BrowserReloadMiddleware", # ... ]
The middleware should be listed after any that encode the response, such as Django’s
GZipMiddleware. The middleware automatically inserts the required script tag on HTML responses before</body>whenDEBUGisTrue.Include
django_browser_reloadURL in your rooturl.py:from django.urls import include, path urlpatterns = [ ..., path("__reload__/", include("django_browser_reload.urls")), ]
Now,
cdto yourTAILWIND_APP_NAMEstatic_srcdirectory. In my case,TAILWIND_APP_NAMEistheme, thus Icdtotheme/static_src:cd theme/static_src
Remove
bs.config.jsfile from thetheme/static_srcdirectory.Open
package.jsonfile intheme/static_srcdirectory, and remove the following commands underscripts:sync,dev:sync,dev.Staying in
package.json, rename thedev:tailwindcommand underscriptstodev. That’s the only command we need for development from now on.Staying in the same directory, uninstall dependencies we don’t need anymore, run the following command:
npm uninstall browser-sync nodemon npm-run-all
Run
python manage.py tailwind startto make sure everything runs properly.