Pim*_*Web 21 php symfony twig assetic
我使用这样的代码生成我的文件
{% block head_stylesheets %}
{% stylesheets
filter='?uglifycss'
'@MyBundle/Resources/public/less/myfile.less'
%}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" media="screen"/>
{% endstylesheets %}
{% endblock head_stylesheets %}
Run Code Online (Sandbox Code Playgroud)
它转储一个名为this的文件: c543k540_myfile_1.css
该文件由资产名称后跟文件名组成: {assetName}_{filename}.css
如何在输出中保留资产名称时自定义输出?
{% block head_stylesheets %}
{% stylesheets
output="css/mynewfilename.{assetName}.css" // <--- Here
filter='?uglifycss'
'@MyBundle/Resources/public/less/myfile.less'
%}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" media="screen"/>
{% endstylesheets %}
{% endblock head_stylesheets %}
Run Code Online (Sandbox Code Playgroud)
更新澄清
我知道如果我使用name选项,在prod中它会编译到myouputname.css
但是我想在debug/dev环境中有什么跟随下面的代码myfile_myouputname_1.css
{% block head_stylesheets %}
{% stylesheets
name="myouputname" // <--- Here
filter='?uglifycss'
'@MyBundle/Resources/public/less/myfile.less'
%}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" media="screen"/>
{% endstylesheets %}
{% endblock head_stylesheets %}
Run Code Online (Sandbox Code Playgroud)
感谢您的回复.
不再建议使用 Assetic 来管理 Symfony 应用程序中的 Web 资产。相反,请使用 Webpack Encore。 https://symfony.com/doc/current/frontend/assetic/index.html#dumping-asset-files
页面特定的 JavaScript 或 CSS(多个条目)如下所述: https: //symfony.com/doc/current/frontend/encore/simple-example.html#multiple-javascript-entries
// webpack.config.js
Encore
// ... general CSS file here...
.addStyleEntry('some_page', './assets/css/assetName.css')
;
Run Code Online (Sandbox Code Playgroud)
支持使用 addStyleEntry(),但不推荐。更好的选择是遵循上面的模式:使用 addEntry() 指向 JavaScript 文件,然后从该文件内部获取所需的 CSS。
归档时间: |
|
查看次数: |
1152 次 |
最近记录: |