Package: django-deno
Denofront-end integration forDjango, version 0.1.4.Currently onlydrollup/terserare supported, the deno server may be extended to support any of deno api, if
applicable.RequirementsDeno 1.19 or newer (which supportsdeno vendorcommand).Django 2.2 / Django 3.2 / Django 4.2 is tested with continuous integration demo appdjk-sample.InstallationIn Ubuntu Linux:curl -fsSL https://deno.land/x/install/install.sh | sh
export DENO_INSTALL=$HOME/.denoIn Windows run PowerShell then invoke:iwr https://deno.land/x/install/install.ps1 -useb | iex

set DENO_INSTALL=%userprofile%\.denoDENO_INSTALLenvironment variable specifies directory whereDenois installed.In case currently installedDenoversion is older than 1.19, please usedeno upgradecommand to install the
newerDenoversion. Older version has nodeno vendorcommand.drollupDeno package was tested with Deno version 1.32.4:deno upgrade --version 1.32.4The package may work with newer versions of Deno, however it was not tested and some versions of Deno (eg. 1.21) are
known to fail to rundrollup, not providing required API.To install the development version ofdjango_denoin python3virtualenv:python -m pip install -U git+https://github.com/Dmitri-Sintsov/django-deno.gitTo install the stable version ofdjango_denoin python3virtualenv:python -m pip install -U git+https://github.com/Dmitri-Sintsov/django-deno.git@v0.1.4Descriptiondjango_denoinstalls deno web service which is used to communicate withDjangoprojects.Currently the web service supports deno version ofrollup.jsbundle (drollup) generation to automatically providees6 modulesbundles forDjangoprojects, including scripts fromDjango packages static files.That enables generation of minifiedterserbundles and / orsystemjsbundles, the later ones are compatible to
IE11.Note that currently it supports onlyes6 modules, not the full transpiling of es5 to es6, so it assumes that
the developing code has es6 imports / exports but the rest of code is written with es5 syntax.AtDjangoside it provides the followingDjango management commands:collectrollupcollectrollup- similar to Djangocollectstaticcommand, but usesdrollupto generate Javascript bundles.It’s preferable to run thecollectrollupcommand this way from theDjangoprojectvirtualenv:python3 manage.py collectrollup --clear --noinput--clearoption is suggested because the target output may vary depending on the source scripts.There isdjk-samplescript for runningcollectrollupin Linux:#!/bin/sh
DJANGO_DEBUG='False' python3 $VIRTUAL_ENV/djk-sample/manage.py collectrollup --noinput --clearhttps://github.com/Dmitri-Sintsov/djk-sample/blob/master/cli/collectrollup.shin Windows:if not defined DENO_INSTALL (
    set DENO_INSTALL=%USERPROFILE%\.deno
)
set "DJANGO_DEBUG=False" & python %VIRTUAL_ENV%/djk-sample/manage.py collectrollup --noinput --clearhttps://github.com/Dmitri-Sintsov/djk-sample/blob/master/cli/collectrollup.cmdThe script also sets the environment variableDJANGO_DEBUGtoFalsewhich is parsed indjk-samplesettings.py:DEBUG = os.environ.get('DJANGO_DEBUG', 'true').lower() in TRUE_STRto set the value ofDENO_OUTPUT_MODULE_TYPEwhich determines the type of Javascript modules generated, eithermodulefor modern browsers that support es6 natively, orSystemJSmodules, which are compatible with IE11:# Do not forget to re-run collectrollup management command after changing rollup.js bundles module type:
DENO_OUTPUT_MODULE_TYPE = 'module' if DEBUG else 'systemjs-module'The additional settings fordrolluprunningcollectrollupmanagement command are specified withDENO_ROLLUP_COLLECT_OPTIONSsetting, which allows to enable / disabletersercompression:# Run $VIRTUAL_ENV/djk-sample/cherry_django.py to check the validity of collectrollup command output bundle.
DENO_ROLLUP_COLLECT_OPTIONS = {
    'terser': True,
}while the default is:DENO_ROLLUP_COLLECT_OPTIONS = {
    # 'relativePaths': True,
    # 'staticFilesResolver': True,
    'terser': True,
    'bundles': getattr(settings, 'DENO_ROLLUP_BUNDLES', {}),
    'moduleFormat': DENO_OUTPUT_MODULE_FORMATS[DENO_OUTPUT_MODULE_TYPE],
}For the full default settings:django_deno settingsrunrolluprunrollup- starts the built-in http development server, similar to Djangorunservercommand, usingdrollupto dynamically generate Javascript bundle in RAM, providing real-timees6 modulescompatibility for IE11.DENO_ROLLUP_SERVE_OPTIONSset the options fordrollupforrunrollupcommand, the default is:DENO_ROLLUP_SERVE_OPTIONS = {
    'inlineFileMap': True,
    'relativePaths': True,
    'preserveEntrySignatures': False,
    'staticFilesResolver': True,
    'withCache': True,
}WhenstaticFilesResolverisTrue,Django packages static filesusesgetStaticFilesResolveratDenoserver side.deno_vendordeno_vendormanagement command generates updateddeno vendorbundle for the built-in deno server. This command
should be used only for package updating / redistribution.Updatingdeno_vendorshould be performed with the following steps:Run the projectcollectrollupcommand with the followingsettings.pyto reload the dependencies:DENO_USE_VENDOR = False
DENO_RELOAD = True
DENO_CHECK_LOCK_FILE = FalseRun the projectcollectrollupcommand with the followingsettings.pyto convertdeno lock.jsontodeno import_map.json:DENO_USE_VENDOR = False
DENO_RELOAD = False
DENO_CHECK_LOCK_FILE = TrueRun the projectdeno_vendorcommand to create localdeno vendor:python3 manage.py deno_vendorRun the projectcollectrollupcommand with the followingsettings.py, to use the updated localdeno_vendor:DENO_USE_VENDOR = True
DENO_RELOAD = False
DENO_CHECK_LOCK_FILE = TrueOptionally override the vendor dir in the repository and make the commit when necessary.BundlesCreation ofrollup.jsbundles has two steps, first one is the definition ofEntry points, second is the
definition ofChunks. Both are specified in Django projectsettings.py.Entry pointsAt the first step, one has to specify Javascript entry points withDENO_ROLLUP_ENTRY_POINTSsetting, for exampledjk-sample settings:DENO_ROLLUP_ENTRY_POINTS = [
    'sample/js/app.js',
    'sample/js/club-grid.js',
    'sample/js/member-grid.js',
]These are the top scripts of es6 module loader hierarchy.Alternatively, the script may specifyuse rollupdirective at the first line of Javascript code, which is used for
Django packages entry points and is discouraged for project entry points.ChunksTo specify manual bundles / chunks,DENO_ROLLUP_BUNDLESsetting is used. For exampledjk-sample settings:DENO_ROLLUP_BUNDLES = {
    'djk': {
        'writeEntryPoint': 'sample/js/app.js',
        'matches': [
            'djk/js/*',
            'djk/js/lib/*',
            'djk/js/grid/*',
        ],
        'excludes': [],
        'virtualEntryPoints': 'matches',
        'virtualEntryPointsExcludes': 'excludes',
    },
}djkkey specifies the chunk name which will result in generation ofdjk.jsbundle.writeEntryPointkey specifies main entry point, which is used to generatedjk.jsbundle.djk.jsbundle is
shared among the some / all ofEntry points, reducing code redundancy.matcheskey specifies the list of matching dirs which scripts that will be included intodjk.jsbundle.excludesspecifies the list of scripts which are excluded from thedjk.jsbundle.virtualEntryPointsspecifies either the list of dirs ormatchesstring value to setes6 modulesvirtual
entry points. Such modules are bundled as a virtual ones, included intodjk.jsbundle only, not being duplicated
as separate standalone module files. SeeisVirtualEntry/setVirtualEntryPointcode for more info.To see the actual settings / usage, demo appsdjk-sampleanddrf-galleryare available.