apnet / assetic-importer-bundle
该包已被弃用且不再维护。没有建议的替代包。
                                        
                    
                    将资源项目集成到 Symfony2
    1.4.0
    2016-07-08 13:17 UTC
Requires
- php: >=5.3.0
- doctrine/lexer: ~1.0
- symfony/assetic-bundle: ~2.3|~3.0
- symfony/config: ~2.3|~3.0
- symfony/dependency-injection: ~2.3|~3.0
- symfony/filesystem: ~2.3|~3.0
- symfony/finder: ~2.3|~3.0
- symfony/http-kernel: ~2.3|~3.0
- symfony/process: ~2.3|~3.0
- symfony/twig-bundle: ~2.3|~3.0
- symfony/yaml: ~2.3|~3.0
- twig/twig: ~1.12
Requires (Dev)
- apnet/coding-standard: ~2.0
- apnet/functional-test-bundle: ~1.2
- covex-nn/twig-callable-bridge-bundle: ~1.1
- knplabs/knp-markdown-bundle: ~1.3
- phpunit/phpunit: ~4.0
- symfony/monolog-bundle: ~2.3
- symfony/symfony: ~2.3|~3.0
Suggests
- symfony/event-dispatcher: ~2.6
This package is not auto-updated.
Last update: 2022-02-01 12:33:38 UTC
README
Bundle 的主要目的是排除 cssrewrite 过滤器,并绕过已知的问题,即当使用 @AcmeFooBundle 语法为 CSS 样式表时,cssrewrite 会失败。
Bundle 允许您通过 assetic 直接将文件从非公共目录导入到 routing。这些文件可以是 外部程序 的结果,或者是由 Symfony 动态创建的。 Bundle 和 assetic 会自动跟踪每个请求中对文件的更改。
安装
将要求添加到 composer.json
{
  "require" : {
    "apnet/assetic-importer-bundle" : "~1.0"
  }
}
注册 Bundle
在 AppKernel.php 文件中注册 Bundle
// ...other bundles ... $bundles[] = new Apnet\AsseticImporterBundle\ApnetAsseticImporterBundle(); if ($this->getEnvironment() == 'dev') { // ...other bundles ... $bundles[] = new Apnet\AsseticWatcherBundle\ApnetAsseticWatcherBundle(); }
配置
假设你在 app/Resources 内有两个目录
- app/Resources/simple_dir包含- style1.css文件
- app/Resources/compass_dir包含- config.rb和其他 compass-project 文件(例如- sass/style2.scss和- stylesheets/style2.css)
然后在你的 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: compass
经过这些更改后,两个 CSS 文件将通过 /app_dev.php 可用
- /app_dev.php/example1/style1.css
- /app_dev.php/example2/stylesheets/style2.css。此外,- css_dir、- images_dir、- javascripts_dir、- fonts_dir中的所有文件都将可用。- sass_dir目录的内容将是私有的。
所有文件都将通过 assetic:dump 命令导出。
Twig
要将在 Twig 模板中包含您的 CSS,请使用 imported_asset 函数
<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" />
Assetic Watcher Bundle
实际上 apnet/assetic-importer-bundle 内有两个 Bundle
- Apnet\AsseticImporterBundle
- Apnet\AsseticWatcherBundle
Watcher 是一个工具,可以与 dev 环境一起使用,以编译 compass 项目,而无需任何外部文件监视器或 IDE。
- 当然,Apache 用户需要 compass_dir/stylesheets目录的写入权限
AsseticWatcherBundle 默认是禁用的。
配置
首先,要启用 Assetic Watcher,请将以下行添加到 config_dev.yml
apnet_assetic_watcher: compiler_root: %kernel.root_dir%/Resources enabled: true
其次,在 config.yml 中添加 watcher 参数到导入的资产配置
apnet_assetic_importer: assets: # ... dir2: source: %kernel.root_dir%/Resources/compass_dir/config.rb target: example2 importer: compass watcher: true