代码之家  ›  专栏  ›  技术社区  ›  dzida

Django:在发布前自动缩小css/js文件

  •  25
  • dzida  · 技术社区  · 15 年前

    一些简单的解决方案是在模板中添加:

    <script src="some_js.{% if not debug %}min.{% endif %}js"....
    

    但这需要手动提供这样的文件存在,并在原始文件更改后手动进行最小化。

    6 回复  |  直到 15 年前
        1
  •  19
  •   JoSSte mirik    4 年前

    你试过了吗 django-compress ?

    看到了吗 http://djangopackages.com/grids/g/asset-managers/

    如果您已经在使用django compress,那么应该考虑升级到django管道,这是一个维护良好的fork,具有许多新特性。我鼓励所有使用django压缩的人改用django管道:* django-pipeline documentation

        2
  •  20
  •   Rick Westera    13 年前

    不再维护Django压缩。尝试 https://github.com/cyberdelia/django-pipeline

        3
  •  8
  •   heyman    14 年前

    我一直在用 webassets 到目前为止我非常满意。我真正喜欢的是,您仍然能够在模板中定义CSS和JS文件,而不是在项目配置中。

    http://elsdoerfer.name/docs/webassets/

        4
  •  4
  •   melchoir55    8 年前

    截至2016年底,这些答案大多已经过时。

    在这里查看一些选项: https://gitlab.com/rosarior/awesome-django#asset-management

    目前, django-compressor

        5
  •  0
  •   jweyrich    12 年前

    this Makefile 缩小和连接我的JS和CSS文件。这取决于天气 YUI Compressor 更新文件后,仍需运行 make

    当然你还需要 {% if not debug %}

    显示简单用法:

    $ make
    [css] static/css/first.css
    [css] static/css/second.css
    [css] static/css/third.css
    [css] static/css/and_so_on.css
    [tag] @import url("static/css/all.css");
    [js] static/js/first.js
    [js] static/js/second.js
    [js] static/js/third.js
    [js] static/js/and_so_on.js
    [tag] <script type="text/javascript" src="static/js/all.js"></script>
    Done.
    
        6
  •  -1
  •   MatthewKremer    12 年前

    刚刚发布了一个开源项目,它监视目录的变化,自动缩小JS,自动编译SASS/SCSS,运行命令行操作,等等。

    去看看吧 http://devWatchr.com/

    它使用 python pyinotify 在你的系统开发过程中。