Skip to content

Instantly share code, notes, and snippets.

@iamjoross
Forked from nathiss/install.sh
Created September 8, 2017 00:42
Show Gist options
  • Save iamjoross/fcbc91bd89689928d379bc28706f00ed to your computer and use it in GitHub Desktop.
Save iamjoross/fcbc91bd89689928d379bc28706f00ed to your computer and use it in GitHub Desktop.
Installing AsseticBundle in Symfony3 (with leafo/scssphp & patchwork/jsqueeze)
# =============================================
# =============== ALERT ===============
# =============================================
# Do NOT run this script!
# It's like a document, it'll NOT work!
# 1. Install AsseticBundle via composer.
composer require symfony/assetic-bundle
# 2. Add AsseticBundle to AppKernel's bundles list:
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
# 3. Add basic configuration to app/config/config.yml
assetic:
debug: '%kernel.debug%'
use_controller: '%kernel.debug%'
filters:
cssrewrite: ~
# 3.1 (optional) If you wish to store yours (e.g. bower's) assets in app/Resources/assets/
# just add their paths with prefix '../app/Resources/assets/'. Example:
assetic:
jquery_and_ui:
inputs:
- "../app/Resources/assets/jquery/dist/jquery.js"
- "../app/Resources/assets/jquery-ui/jquery-ui.js"
bootstrap_js:
inputs:
- "../app/Resources/assets/bootstrap/dist/js/bootstrap.js"
bootstrap_css:
inputs:
- "../app/Resources/assets/bootstrap/css/bootstrap.css"
font_awesome_css:
inputs:
- "../app/Resources/assets/font-awesome/css/font-awesome.css"
# 4. To use those files add this code to your twig template:
{% stylesheets
'@bootstrap_css'
'@font-awesome'
output='assets/css/main.css' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
# ... and java script:
{% javascripts
'@jquery_and_ui'
'@bootstrap_js'
output='assets/js/main.js' %}
<script src="{{ asset_url }}"></script>
{% endjavascritps %}
# 5. If you wish to use SCSS and to compress javascript's files you should install these packages:
$ composer require leafo/scssphp patchwork/jsqueeze
# ... and configure it (app/config/config.yml):
assetic:
filters:
scssphp:
formatter: 'Leafo\ScssPhp\Formatter\Compressed'
jsqueeze: ~
# 5.1 To auto-compile yours scss's files (inside your Bundle) edit stylesheets block:
{% stylesheets
'@bootstrap_css'
'@font_awesome_css'
'@BlogBundle/Resources/assets/scss/*'
filter='scssphp'
output='assets/css/main.css' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
# 5.2 To auto-compress yours js's files (inside your Bundle) edit javascritps block:
{% javascripts
'@jquery_and_ui'
'@bootstrap_js'
'@BlogBundle/Resources/assets/js/*'
filter='?jsqueeze'
output='assets/js/main.js' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
# '?' char inside filter means it'll be active only in prod enviroment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment