每次重新加载页面时,如何强制Assetic渲染资产? [英] How can I force assetic to render assets each time the page is reloaded?

查看:137
本文介绍了每次重新加载页面时,如何强制Assetic渲染资产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次重新加载页面时(无论是否修改资产),我如何强制Assetic渲染资产?

How can I force assetic to render assets each time the page is reloaded (no matter if assets are modified or not)?

有关我的问题的更多解释:

More explanation about my issue:

我目前正在研究Symfony2项目,在这里我使用Assetic来管理和编译.less文件.我一切正常,但是我有一个小问题要解决.

I'm currently working on a Symfony2 project where I use Assetic to manage and compile .less files. I got everything to work fine but I'm having a small issue that I'd like to fix.

在config.yml中,我将资产use_controller设置为true.

In config.yml, I set the assetic use_controller to true.

# Assetic Configuration
assetic:
debug:          %kernel.debug%
use_controller: true

结果是,每次修改.less文件时,Symfony都会动态呈现新的.css文件.太好了.

The result is that Symfony dynamically renders the new .css files each time .less files are modified. This is great.

我的问题是我使用了一个主project.less文件,在其中导入了所有其他.less文件

My problem is that I use a main project.less file where I import all the other .less files

// Import Twitter Bootstrap
@import "../../../../../../vendor/twitter/bootstrap/less/bootstrap.less";

// Import Foo
@import "foo.less";

...

它可以使我保持整洁的结构,还可以从供应商处导入.less文件,例如twitter bootstrap.

it allows me to keep a clean structure and also to import .less files from vendors, e.g: twitter bootstrap.

在我的Twig模板中,我仅调用此主文件.

In my Twig template, I only call this main file.

{% stylesheets '@ProjectWebBundle/Resources/public/less/project.less' filter='less' %}
        <link rel="stylesheet" type="text/css" media="screen" href="{{ asset_url }}" />
{% endstylesheets %}    

由于此主.less文件从未修改,因此Assetic不会重新编译资产.因此,无论文件是否被修改,我都希望它能使文件呈现无关紧要.

Since this main .less file is never modified, Assetic doesn't recompile the assets. This is why I'd like it to render the files not matter if they've been modified or not.

推荐答案

AFAIK对此

我使用:

php app/console assetic:dump --watch

每当它检测到模板上引用的任何.less文件中的更改时,它将编译.less文件.

which will compile your .less files each time it detects a change in any of the .less files referenced on your templates.

强制编译,您必须在主"文件(@导入其他文件)中进行任何更改.但是,好消息是,足以触摸"文件来做到这一点.因此,您可以在每次需要时手动触摸它:

To force a compilation you have to make any change in your "main" file (the file that @imports the others). But, the good news are that is just enough to "touch" the file to do that. So you can just manually touch it every time you need:

touch ~/web/css/main.less;

或者,我通常要做的是设置一个脚本,该脚本每60秒左右触摸一次此主"文件:

Or, what i usually do is to set up a script that touches this "main" file each 60 seconds or so:

while true; do
    sleep 60
    touch ~/web/css/main.less
done

这应该可以在linux和mac上运行.

This should work on linux and mac.

希望它会有所帮助.至少是暂时的:)

Hope it helps. At least temporarily :)

这篇关于每次重新加载页面时,如何强制Assetic渲染资产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆