Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set default dev_server_port to 5173 #99

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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