让 django-compressor 在非生产环境中单独留下 <script type="module">

Have django-compressor leave <script type="module"> alone in non-production

为了开发(没有 DJANGO_PRODUCTION)我想保留 ES6 模块原样,这意味着如果某些东西是

{% compress js %}
  <script src="{% static "path/to/some.js" %}" type="module"></script>
{% endcompress %}

之后应该还是type="module"

COMPRESS_ENABLED 设置为 False 是不够的,如果我删除 module 预编译器,那么我将得到 "Couldn't find any precompiler in COMPRESS_PRECOMPILERS setting for mimetype 'module'." 错误信息。现在我可以将 cat 用作预编译器 (COMPRESS_PRECOMPILERS = (('module', 'cat'),)),但脚本标签仍会更改并删除 type="module"

那么有什么方法可以轻松防止这种情况发生吗?最好没有太多非生产案例的特殊案例?

the official docs所述:

When COMPRESS_ENABLED is False the input will be rendered without any compression except for code with a mimetype matching one listed in the COMPRESS_PRECOMPILERS setting

可以做的是为开发创建不同的 COMPRESS_PRECOMPILERS 设置。

例如:

DEBUG = not os.environ.get('DJANGO_PRODUCTION')

if not DEBUG:
    COMPRESS_PRECOMPILERS = (
        ('module', 'browserify {infile} -t babelify --outfile {outfile}'),
    )