Skip to main content

django-simple-vite

A simple Django app to integrate Vite.js easily in your Django project.

Install:

pip install django-simple-vite

Then add simple_vite to INSTALLED_APPS in Django settings.

INSTALLED_APPS = [
    ...
    'simple_vite',
    ...
]

Settings:

During development, set VITE_SERVER_URL in Django settings, pointing to the Vite.js development server, e.g.:

VITE_SERVER_URL = 'http://localhost:3000'

When in production, you don't need to set VITE_SERVER_URL, because the compiled assets produced by Vite.js will be served as regular static files.

Usage:


Create an app that will contain your Vite.js powered frontend:

./manage.py startapp frontend

Inside your app, create a vite_src directory (the name is arbitrary). This directory will contain your Javascript sources, that will be compiled by Vite.js.

In the vite_src directory, create a vite.config.js file, with this content:

const { resolve } = require('path');

export default {
    build: {
        manifest: true, // adds a manifest.json
        rollupOptions: {
            input: [
              // Use main.js file as entrypoint for your JS app.
              resolve(__dirname, './main.js'),
            ]
        },
        // Puts the Vite.js manifest.json in
        // PROJECT_ROOT/frontend/static/
        outDir:  '../static',
        // puts compiled asset files (js, css) in
        // PROJECT_ROOT/frontend/static/frontend
        assetsDir:  'frontend',
    },
    plugins: [],
    server: {
        // This port should match with VITE_SERVER_URL Django setting.
        port: 3000,
        open: false,
    }
};

In the vite_src directory, create a main.js file, that will serve as entry point for your app, with this content:

// Add this at the beginning of your app entry.
import 'vite/modulepreload-polyfill';
import 'main.css';

console.log("hello world");

main.css is a CSS file that will be imported by Vite and used by your application.

Install Vite.js in your vite_src directory:

yarn add vite

Add a couple of script in your package.json:

{
  "dependencies": {
    "vite": "^4.1.4"
  },
  "scripts": {
    "dev": "vite",
    "build": "vite build"
  }
}

Launch Vite.js server:

yarn dev

Create a Django template index.html that will hold the HTML markup used by your application, save it inside your frontend Django app in a subdirectory templates/frontend/.

{% load vite %}

<html>
<head>
    {% vite_styles 'main.js' %}
</head>
<body>
    <h1>Hello world</h1>

    {% vite_scripts 'main.js' %}
</body>

</html>

Now create a Django URLConf that will serve the above template, and you'll see a basic Vite.js powered web app, with Hot Module Replacement (HMR) enabled!

Metadata

Release files for django-simple-vite 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-simple-vite 1.0.0
File Size Uploaded Provenance Actions
django-simple-vite-1.0.0.tar.gz 4.6 kB Without provenance Details for django-simple-vite-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-simple-vite 1.0.0
File Interpreter ABI Platform Actions
django_simple_vite-1.0.0-py3-none-any.whl Python 3 none any Details for django_simple_vite-1.0.0-py3-none-any.whl

Total release size: 9.3 kB

Release files / django-simple-vite-1.0.0.tar.gz

Download URL django-simple-vite-1.0.0.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b41f5c479209e7d712afb9f83757bc415d3cd05f7f0ec42304411667377012b0
BLAKE2b-256 checksum
How to use checksums
607062a0eabf4db4396853869181dbe2d4d22d3bc9bd8ba70284fae1f8d2c5d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / django_simple_vite-1.0.0-py3-none-any.whl

Download URL django_simple_vite-1.0.0-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c775f117650591128bae88ab7343f7bbd2e3833fbc7284820172c1f77f5addac
BLAKE2b-256 checksum
How to use checksums
0c38c112586541e19563a73d2c4db8b8e3b433598947083f6e2b174a6ed1fcdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Security for django-simple-vite 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page