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

changing port is not reflected in vite_asset tag #143

Open
JianDk opened this issue Aug 6, 2024 · 1 comment
Open

changing port is not reflected in vite_asset tag #143

JianDk opened this issue Aug 6, 2024 · 1 comment

Comments

@JianDk
Copy link

JianDk commented Aug 6, 2024

I wanted to change the port to 5174 instead of its standard at 5173. I have updated the change in my settings.py by adding this line

DJANGO_VITE_DEV_SERVER_PORT =5174

then in vite.config.js I have updated the server port to 5174 as below

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  root: resolve('./assets/'),
  base: '/static/',
  server: {
    host: 'localhost',
    port: 5174,
    open: false,
    watch: {
      usePolling: true,
      disableGlobbing: false,
    },
  },
  resolve: {
    extensions: ['.js', '.json', '.jsx', '.ts', '.tsx'],
  },
  build: {
    outDir: resolve('./static/dist'),
    assetsDir: '',
    manifest: true,
    emptyOutDir: true,
    target: 'es2015',
    rollupOptions: {
      input: {
        main: resolve('./assets/js/main.jsx'),
      },
      output: {
        chunkFileNames: undefined,
      },
    },
  },
})

In my template I found that vite_asset is still pointing to 5173 instead of 5174. Below is my template.html

{% extends 'baseTemplate.html' %}
{% load static %}
{% load django_vite %}

{% block head %}
{% vite_hmr_client %}
{% vite_react_refresh %}
{% endblock %}

{% block content %}
{% include 'mainViewNavbar.html' %}
<div class="bg-sky-100">
<div id="dissolution_plot"></div>
</div>
{% endblock %}

{% block script %}
{% vite_asset 'js/main.jsx' %}
{% endblock %}

the source code snippet from the rendered page shows

<script type="module" src="http://localhost:5173/static/js/main.jsx"></script>

where I am expecting port 5174 as below

<script type="module" src="http://localhost:5174/static/js/main.jsx"></script>

I have tried to restart both my django and vite servers and also cleared the cookies, but with the same result. My django-vite is version 3.0.4.

@MrBin99
Copy link
Owner

MrBin99 commented Aug 8, 2024

Hi,

Since you are in the latest version of django-vite can you use the new way of defining settings (https://github.com/MrBin99/django-vite?tab=readme-ov-file#configuration) as this way will be deprecated at some point.

If it still doesn't work please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants