使用PHP類庫來壓縮JS,CSS文件

##安裝PHP類庫 composer require leafo/scssphp composer require patchwork/jsqueeze:"~1.0"javascript

##合併壓縮CSS文件php

####配置 assetic: filters: scssphp: formatter: 'Leafo\ScssPhp\Formatter\Compressed'css

####模板中使用java

{% stylesheets filter="scssphp" output="css/app.css"
        "assets/scss/bootstrap.scss"
        "assets/scss/font-awesome.scss"
        "assets/css/*.css"
    %}
        <link rel="stylesheet" href="{{ asset_url }}" />
    {% endstylesheets %}

##合併壓縮JS文件jquery

####配置 assetic: filters: jsqueeze: ~ # ...bootstrap

####模板中使用app

{% javascripts filter="?jsqueeze" output="js/app.js"
    "assets/js/jquery.js"
    "assets/js/bootstrap.js"
    "assets/js/main.js"
    %}
    <script src="{{ asset_url }}"></script>
    {% endjavascripts %}

##注意composer

須要注意在debug模式下是沒有效果的;能夠在生產環境下看結果; php app/console assetic:dump --env=prod php app/console cache:clear --env=produi

相關文章
相關標籤/搜索