From c040fd4706b56be62418f46323bb60431c65a5ad Mon Sep 17 00:00:00 2001 From: Niicck Date: Tue, 14 Nov 2023 15:22:07 -0800 Subject: [PATCH] set default dev_server_port to 5173 --- README.md | 11 ++++------- django_vite/core/asset_loader.py | 2 +- tests/tests/templatetags/test_vite_asset.py | 4 ++-- tests/tests/templatetags/test_vite_asset_url.py | 2 +- tests/tests/templatetags/test_vite_hmr_client.py | 2 +- tests/tests/templatetags/test_vite_react_refresh.py | 4 ++-- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f1ea1c9..615b27c 100644 --- a/README.md +++ b/README.md @@ -99,8 +99,7 @@ Define a default `DJANGO_VITE` configuration in your `settings.py`. ```python DJANGO_VITE = { "default": { - "dev_mode": True, - "dev_server_port": 5173, + "dev_mode": True } } ``` @@ -109,7 +108,6 @@ Or if you prefer to use the legacy module-level settings, you can use: ```python DJANGO_VITE_DEV_MODE = True -DJANGO_VITE_DEV_SERVER_PORT = 5173 ``` Be sure that the `build.outDir` from `vite.config.js` is included in `STATICFILES_DIRS`. @@ -189,7 +187,7 @@ If you're using React, this will generate the Javascript needed to support React ### Custom attributes -By default, all scripts tags are generated with a `type="module"` and `crossorigin=""` attributes just like ViteJS do by default if you are building a single-page app. +By default, all script tags are generated with a `type="module"` and `crossorigin=""` attributes just like ViteJS do by default if you are building a single-page app. You can override this behavior by adding or overriding this attributes like so : ``` @@ -248,7 +246,6 @@ If you would like to use django-vite with multiple vite configurations you can s DJANGO_VITE = { "default": { "dev_mode": True, - "dev_server_port": 5173 }, "external_app_1": { ... @@ -298,7 +295,7 @@ The `server.host` in `vite.config.js` for the ViteJS development server. ### dev_server_port - **Type**: `int` -- **Default**: `3000` +- **Default**: `5173` - **Legacy Key**: `DJANGO_VITE_DEV_SERVER_PORT` The `server.port` in `vite.config.js` for the ViteJS development server. @@ -361,7 +358,7 @@ If you're using React, this will generate the Javascript needed to support React ## Notes -- In production mode, all generated path are prefixed with the `STATIC_URL` +- In production mode, all generated paths are prefixed with the `STATIC_URL` setting of Django. ### Whitenoise diff --git a/django_vite/core/asset_loader.py b/django_vite/core/asset_loader.py index acc57f1..5998cc3 100644 --- a/django_vite/core/asset_loader.py +++ b/django_vite/core/asset_loader.py @@ -33,7 +33,7 @@ class DjangoViteConfig(NamedTuple): dev_server_host: str = "localhost" # Default Vite server port. - dev_server_port: int = 3000 + dev_server_port: int = 5173 # Prefix for STATIC_URL. static_url_prefix: str = "" diff --git a/tests/tests/templatetags/test_vite_asset.py b/tests/tests/templatetags/test_vite_asset.py index 6adc93c..3c7053d 100644 --- a/tests/tests/templatetags/test_vite_asset.py +++ b/tests/tests/templatetags/test_vite_asset.py @@ -27,7 +27,7 @@ def test_vite_asset_returns_dev_tags(as_default): html = template.render(Context({})) soup = BeautifulSoup(html, "html.parser") script_tag = soup.find("script") - assert script_tag["src"] == "http://localhost:3000/static/src/entry.ts" + assert script_tag["src"] == "http://localhost:5173/static/src/entry.ts" assert script_tag["type"] == "module" @@ -121,7 +121,7 @@ def test_vite_asset_dev_prefix(patch_settings): soup = BeautifulSoup(html, "html.parser") script_tag = soup.find("script") assert ( - script_tag["src"] == "http://localhost:3000/static/custom/prefix/src/entry.ts" + script_tag["src"] == "http://localhost:5173/static/custom/prefix/src/entry.ts" ) assert script_tag["type"] == "module" diff --git a/tests/tests/templatetags/test_vite_asset_url.py b/tests/tests/templatetags/test_vite_asset_url.py index e717846..c84c6c3 100644 --- a/tests/tests/templatetags/test_vite_asset_url.py +++ b/tests/tests/templatetags/test_vite_asset_url.py @@ -15,7 +15,7 @@ def test_vite_asset_url_returns_dev_url(): html = template.render(Context({})) soup = BeautifulSoup(html, "html.parser") script_tag = soup.find("script") - assert script_tag["src"] == "http://localhost:3000/static/src/entry.ts" + assert script_tag["src"] == "http://localhost:5173/static/src/entry.ts" @pytest.mark.usefixtures("dev_mode_false") diff --git a/tests/tests/templatetags/test_vite_hmr_client.py b/tests/tests/templatetags/test_vite_hmr_client.py index 2a647ca..faf4e76 100644 --- a/tests/tests/templatetags/test_vite_hmr_client.py +++ b/tests/tests/templatetags/test_vite_hmr_client.py @@ -14,7 +14,7 @@ def test_vite_hmr_client_returns_script_tag(): html = template.render(Context({})) soup = BeautifulSoup(html, "html.parser") script_tag = soup.find("script") - assert script_tag["src"] == "http://localhost:3000/static/@vite/client" + assert script_tag["src"] == "http://localhost:5173/static/@vite/client" assert script_tag["type"] == "module" diff --git a/tests/tests/templatetags/test_vite_react_refresh.py b/tests/tests/templatetags/test_vite_react_refresh.py index 41261fb..aa82cf6 100644 --- a/tests/tests/templatetags/test_vite_react_refresh.py +++ b/tests/tests/templatetags/test_vite_react_refresh.py @@ -18,7 +18,7 @@ def test_vite_react_refresh_returns_script_tag(): assert script_tag.has_attr("type") assert script_tag["type"] == "module" assert "__vite_plugin_react_preamble_installed__" in script_tag.text - assert "http://localhost:3000/static/@react-refresh" in script_tag.text + assert "http://localhost:5173/static/@react-refresh" in script_tag.text @pytest.mark.parametrize( @@ -105,4 +105,4 @@ def test_vite_react_refresh_url_setting(patch_settings): html = template.render(Context({})) soup = BeautifulSoup(html, "html.parser") script_tag = soup.script - assert "http://localhost:3000/static/foobar" in script_tag.text + assert "http://localhost:5173/static/foobar" in script_tag.text