Skip to content

Commit

Permalink
set default dev_server_port to 5173
Browse files Browse the repository at this point in the history
  • Loading branch information
Niicck committed Nov 14, 2023
1 parent 49e1115 commit c040fd4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 14 deletions.
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
```
Expand All @@ -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`.
Expand Down Expand Up @@ -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 :
```
Expand Down Expand Up @@ -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": {
...
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion django_vite/core/asset_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/templatetags/test_vite_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion tests/tests/templatetags/test_vite_asset_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/templatetags/test_vite_hmr_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
4 changes: 2 additions & 2 deletions tests/tests/templatetags/test_vite_react_refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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

0 comments on commit c040fd4

Please sign in to comment.