MrBin99 / django-vite

Integration of ViteJS in a Django project.
Apache License 2.0
537 stars 71 forks source link

changing port is not reflected in vite_asset tag #143

Open JianDk opened 1 month ago

JianDk commented 1 month ago

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

where I am expecting port 5174 as below

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 commented 1 month ago

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.