The main purpose of a Bundle is to exclude cssrewrite filter and to bypass known issue
that causes the cssrewrite to fail when using the @AcmeFooBundle syntax for CSS Stylesheets.
Bundle allows you to import files from non-public directories via assetic directly into routing.
These files can either be a result of an external program, or created on the fly from Symfony.
Bundle и assetic keep track of changes to files automatically on every request.
Add requirements to composer.json:
{
  "require" : {
    "apnet/assetic-importer-bundle" : "~1.0"
  }
}Register the bundle in the AppKernel.php file
// ...other bundles ...
$bundles[] = new Apnet\AsseticImporterBundle\ApnetAsseticImporterBundle();
if ($this->getEnvironment() == 'dev') {
    // ...other bundles ...
    $bundles[] = new Apnet\AsseticWatcherBundle\ApnetAsseticWatcherBundle();
}Let's assume that you have two directories inside app/Resources:
- app/Resources/simple_dirwith- style1.cssfile
- app/Resources/compass_dirwith- config.rband all other compass-project files (e.g.- sass/style2.scssand- stylesheets/style2.css)
Then add the configuration into your config.yml
apnet_assetic_importer:
    assets:
        dir1:
            source: %kernel.root_dir%/Resources/simple_dir
            target: example1
        dir2:
            source: %kernel.root_dir%/Resources/compass_dir/config.rb
            target: example2
            importer: compassAfter these changes two css files will be accessible via /app_dev.php
- /app_dev.php/example1/style1.css
- /app_dev.php/example2/stylesheets/style2.css. Also all files inside- css_dir,- images_dir,- javascripts_dir,- fonts_dirwill ba available.- sass_dirdirectory contents will be private.
All files will be dumped with assetic:dump command.
To include your CSS into Twig template use imported_asset function:
<link href="{{ imported_asset('example1/style1.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ imported_asset('example2/stylesheets/style2.css') }}" rel="stylesheet" type="text/css" />Actualy there are two bundles inside apnet/assetic-importer-bundle:
- Apnet\AsseticImporterBundle
- Apnet\AsseticWatcherBundle
Watcher is a tool, that could be used with dev environment to compile
compass project without any external file watchers or IDE.
- Of course Apache user needs write permissions to the compass_dir/stylesheetsdirectory
AsseticWatcherBundle is disabled by default.
First, to enable Assetic Watcher add these lines to config_dev.yml
apnet_assetic_watcher:
    compiler_root: %kernel.root_dir%/Resources
    enabled: trueAnd second, add watcher parameter to imported asset configuration in config.yml
apnet_assetic_importer:
    assets:
        # ...
        dir2:
            source: %kernel.root_dir%/Resources/compass_dir/config.rb
            target: example2
            importer: compass
            watcher: true
