經過UglifyJS,UglifyCSS縮小js,css文件

##UglifyJS安裝與使用 ###安裝 ####全局安裝 npm install -g uglify-js ####本地安裝 進入到symfony項目目錄 npm install uglify-js --prefix app/Resourcesjavascript

###配置過濾器 # app/config/config.yml assetic: node:/usr/bin/node //配置node執行路徑 filters: uglifyjs2: # the path to the uglifyjs executable bin: /usr/local/bin/uglifyjs #若是是本地安裝 bin: "%kernel.root_dir%/Resources/node_modules/uglify-js/bin/uglifyjs"css

###使用 {% javascripts '@AppBundle/Resources/public/js/*' filter='uglifyjs2' %} <script src="{{ asset_url }}"></script> {% endjavascripts %}java

##UglifyCSS安裝與使用node

###安裝 # 全局 $ npm install -g uglifycssnpm

# 本地
$ cd /path/to/your/symfony/project
$ npm install uglifycss --prefix app/Resources

###配置app

# app/config/config.yml
assetic:
    filters:
        uglifycss:
            bin: /usr/local/bin/uglifycss
        #bin: "%kernel.root_dir%/Resources/node_modules/uglifycss/uglifycss"

###使用 {% stylesheets 'bundles/App/css/*' filter='uglifycss' filter='cssrewrite' %} <link rel="stylesheet" href="{{ asset_url }}" /> {% endstylesheets %}url

##注意 若是想要在debug開啓時不縮小過濾器使用 "?"前綴(filter="?csswrite",fliter="?uglifyjs2")ssr

相關文章
相關標籤/搜索