django-compressor在非生产中单独留下<script type =“module”>

时间:2018-03-21 17:12:16

标签: django django-staticfiles es6-modules django-compressor

对于开发(没有 DJANGO_PRODUCTION )我想按原样保留ES6模块,这意味着如果有什么东西

&#xA;&#xA;
  {%compress js%}&#xA; &lt; script src =“{%static”path / to / some.js“%}”type =“module”&gt;&lt; / script&gt;&#xA; {%endcompress%}&#xA;  
&#xA;&#xA;

之后它应该仍然是 type =“module”

&#xA;&#xA;

设置 COMPRESS_ENABLED False 是不够的,如果我删除 module 预编译器,那么我得到“找不到任何预编译器COMPRESS_PRECOMPILERS设置mimetype'module'。“错误消息。现在我可以使用 cat 作为预编译器( COMPRESS_PRECOMPILERS =(('module','cat'),))但脚本标签仍然会被更改并且 type =“module”已删除。

&#xA;&#xA;

那么我有什么方法可以轻易地阻止它?最好没有太多特殊外壳的非生产情况?

&#xA;

1 个答案:

答案 0 :(得分:2)

the official docs中所述:

  

当COMPRESS_ENABLED为False时,如果代码的mimetype与COMPRESS_PRECOMPILERS设置中列出的代码匹配,则输入将在没有任何压缩除外)的情况下呈现

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

E.g:

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

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