问题描述
有什么方法可以告诉 Assetic 命令行文件在为开发环境构建时不生成复合输出"文件?
Is there any way to tell the Assetic command-line file to not generate the composite "output" file when it builds for the dev environment?
我们使用 --watch 配置运行它.我们有合成文件需要很长时间才能生成并且没有被使用,所以这是一种严重的时间浪费.它还导致它重新生成该堆栈中的所有文件,而不是更改的单个文件.
We have it running with the --watch configuration. We have composite files which take a long time to generate and aren't used, so it's a serious waste of time. It also causes it to regenerate all files in that stack, instead of the one single one that changes.
有什么想法吗?如果没有,我很想自己覆盖 asset:dump 命令,因为每次进行微小的文件更改时,我们都会严重浪费 1-3 分钟.=(
Any ideas? If there isn't, I'm half-tempted to override the asset:dump command myself because we're seriously wasting 1-3 minutes every time we make a tiny file change. =(
Symfony 版本:2.2.0(根据调试栏,只运行 Composer 更新,没有任何变化)
Symfony version: 2.2.0 (according to debug bar, just ran Composer update with no changes)
config.yml (assetic 块)
config.yml (assetic block)
assetic:
debug: %kernel.debug%
use_controller: false
#bundles: []
#java: /usr/bin/java
filters:
cssrewrite: ~
less:
node: /usr/bin/node
node_paths: [/usr/local/lib/node_modules,/usr/lib/node_modules]
apply_to: "\.less"
typescript:
resource: %kernel.root_dir%/../src/GamePlan/Bundle/CoreBundle/Resources/config/assetic.typescript.xml
apply_to: "\.ts"
tsc: /usr/local/bin/tsc
node: /usr/bin/node
useOut: false
(自定义 TypeScriptFilter,但它也发生在 CSS 文件中,所以它不应该是导致它的原因......这也是对官方存储库中的一个相对较小的调整.)
(Custom TypeScriptFilter, but it is happening to CSS files as well, so it shouldn't be that which is causing it... it's also a relatively minor tweak to the one in the official repo.)
config_dev.yml (assetic 块)
config_dev.yml (assetic block)
assetic:
use_controller: false
示例用法:
{% stylesheets output="bundles/mybundle/styles/mystyle.css"
filter="cssrewrite"
"@MyBundle/Resources/styles/a.less"
"@MyBundle/Resources/styles/b.less"
"@MyBundle/Resources/styles/subfolder/*.less"
"@MyBundle/Resources/styles/subfolder/*/*.less"
%}
<link type="text/css" rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}
运行命令(从/var/www 作为 www-data):
Running command (from /var/www as www-data):
php Symfony/app/console assetic:dump --env=dev [--watch]
无论有没有 --watch 都不会改变生成的文件,只是如果它全部执行或只是监视.
With or without --watch doesn't change what files are generated, just if it does them all or just watches.
请注意,这是否会给任何人提供有关正在发生的事情的线索,但它会尝试在生成单个开发文件之前生成复合文件.
Note sure if this will give anyone a clue as to what is going on, but it tries to generate the composite file before it generates the individual dev ones.
我还确保我没有复制任何包含、引用其他块中的任何复合文件等.
I've also ensured I'm not duplicating any includes, referencing any composite files in other blocks, etc.
它没有加载 HTML 中的复合文件,但我可以看到它们是从命令生成的.
It isn't loading the composite files in the HTML, but I can see them generated from the command.
如果需要更多信息,请告诉我.谢谢.
If any more info is needed, please let me know. Thanks.
推荐答案
所以我最终完成了 Assetic 包的 DumpCommand.事实证明,无论环境如何,它们总是无条件生成的(如果我们处于调试模式,只有有条件地只执行开发).
So I ended up going through the DumpCommand for the Assetic bundle. It turns out they are always unconditionally generated, regardless of environment (there is only a conditional to only do the dev ones if we are in debug mode).
为了自己修复它,我只是复制了那个 DumpCommand 并制作了我自己的版本,我最终在上面添加了一个条件,所以它只在环境是 prod 时才这样做.我也做了它,所以它只会在该文件发生更改时转储开发文件.
To fix it myself, I just copied that DumpCommand and made my own version which I ended up adding a condition to the above so it only does it if the environment is prod. I also made it so it'll only dump the dev files if that file has changed.
这个解决方案并不完美,需要注意(例如,如果一个文件依赖于另一个文件,它不会被重新编译,所以如果我有编译器错误,我必须不时运行原始文件).但是,它对我有用.
This solution isn't perfect and requires paying attention (for example, if one file depends on another, it won't get recompiled so I have to run the original still from time to time if I have a compiler error). However, it works for me.
修改后的 dumpAsset() 如下所示:
The modified dumpAsset() looks like this:
private function dumpAsset($name, OutputInterface $output)
{
$asset = $this->am->get($name);
$formula = $this->am->getFormula($name);
if (!$this->am->isDebug()) {
// start by dumping the main asset
$this->doDump($asset, $output);
}
// dump each leaf if debug
if (isset($formula[2]['debug']) ? $formula[2]['debug'] : $this->am->isDebug()) {
foreach ($asset as $leaf) {
$mtime = filemtime(($leaf->getSourceRoot() ? $leaf->getSourceRoot() . DIRECTORY_SEPARATOR : '') . $leaf->getSourcePath());
if ($mtime >= $asset->getLastModified()) {
$this->doDump($leaf, $output);
}
}
}
}
这篇关于Symfony2 Assetic 不在 --env=dev 上生成复合文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!