1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
Django-yarnpkg
==============
Easy way to use `yarnpkg <https://yarnpkg.com/>`_ with your `Django <https://www.djangoproject.com/>`_ project.
This is a fork of `django-bower <https://github.com/nvbn/django-bower>` by Vladimir Iakovlev.
Read full documentation on `read-the-docs <https://django-yarnpkg.readthedocs.io/en/latest/>`_.
Installation
------------
Install django-yarnpkg package:
.. code-block:: bash
pip install django-yarnpkg
Add django-bower to `INSTALLED_APPS` in your settings:
.. code-block:: python
'django_yarnpkg',
Add staticfinder to `STATICFILES_FINDERS`:
.. code-block:: python
'django_yarnpkg.finders.NodeModulesFinder',
Specify path to components root (you need to use an absolute path):
.. code-block:: python
NODE_MODULES_ROOT = os.path.join(BASE_DIR, 'node_modules')
If you need, you can manually set the path to yarnpkg:
.. code-block:: python
YARN_PATH = '/usr/bin/yarnpkg'
You can see an example settings file in `example project <https://edugit.org/AlekSIS/libs/django-yarnpkg/blob/master/example/example/settings.py>`_.
Usage
-----
Specify `YARN_INSTALLED_APPS` in settings, like:
.. code-block:: python
YARN_INSTALLED_APPS = (
'bootstrap@^4.4.1',
'underscore@^1.6.1',
)
Download yarn packages with the management command:
.. code-block:: bash
./manage.py yarn install
Add scripts in the template, like:
.. code-block:: html+django
{% load static %}
<script type="text/javascript" src='{% static 'jquery/dist/jquery.js' %}'></script>
In production you need to call `yarnpkg install` before `collectstatic`:
.. code-block:: bash
./manage.py yarn install
./manage.py collectstatic
If you need to pass arguments to yarnpkg, like `--flat`, use:
.. code-block:: bash
./manage.py yarn install -- --flat
You can call yarnpkg commands like `info` and `update` with:
.. code-block:: bash
./manage.py yarn info backbone
./manage.py yarn update
Python 3 support
----------------
django-yarnpkg supports python 3.3+
|