Skip to content

changing port is not reflected in vite_asset tag #143

@JianDk

Description

@JianDk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions