Skip to content
This repository has been archived by the owner on Jul 20, 2021. It is now read-only.
/ django-encore Public archive

Django integration with Webpack Encore

License

Notifications You must be signed in to change notification settings

egorsmkv/django-encore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django Encore

This library integrates Webpack Encore into your Django application like it does Webpack Encore Bundle for Symfony.

Usage

  1. Install the library from PyPI:
pip install django-encore
  1. Configure your settings.py file:

Include the library:

INSTALLED_APPS = [
    # ...
    'encore',
]

Add ENCORE_ENTRYPOINTS_FILE and change STATICFILES_DIRS:

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'assets_build'),
]

ENCORE_ENTRYPOINTS_FILE = os.path.join(BASE_DIR, 'assets_build') + '/build/entrypoints.json'
  1. Use template tags in your templates:
{% load encore %}

{% block javascripts %}
    {{ block.super }}
    {% encore_entry_script_tags 'demo1' %}
{% endblock %}

{% block stylesheets %}
    {{ block.super }}
    {% encore_entry_link_tags 'demo1' %}
{% endblock %}

See the example folder for more details.

Development

First of all, install dependencies by pipenv:

cd example/webapp

pipenv install --dev
pipenv shell # to shell with virtual environment

Second, build files using Encore:

npm run dev

Then you can start the web server:

python manage.py runserver