adrenalinkin / custom-assets-bundle
提供从自定义源创建资源的功能。类似于 assets:install 命令。
Requires
- php: ~5.6||~7.0
- adrenalinkin/config-helper: ~1.0,>=1.0.5
- sensio/distribution-bundle: ~3.0||~4.0||~5.0
- symfony/framework-bundle: ~2.5||~3.0
Suggests
- symfony/symfony: Allows more advanced functionality with full Symfony package
README
简介
该包允许将所需的资源从自定义文件夹传输到公共目录。业务逻辑类似于标准的 Symfony 命令 - assets:install
。还需要 YAML 配置,该配置注册一个或多个自定义源路径。安装后,源将被传输到项目公共部分的 custom_assets
文件夹下。
安装
步骤 1:下载包
打开命令行,进入您的项目目录,并执行以下命令以下载此包的最新稳定版本
composer require adrenalinkin/custom-assets-bundle
此命令要求您全局安装 Composer。
步骤 2:启用包
然后,通过更新您的 app/AppKernel.php
文件来启用包
<?php // app/AppKernel.php class AppKernel extends Kernel { // ... public function registerBundles() { $bundles = [ // ... new Linkin\Bundle\CustomAssetsBundle\LinkinCustomAssetsBundle(), ]; return $bundles; } // ... }
步骤 3:通过 Composer 运行命令
在 composer.json
中注册脚本,以便在 composer requirements 安装/更新时调用自定义资源安装。为此行为添加字符串 "Linkin\\Bundle\\CustomAssetsBundle\\Composer\\ScriptHandler::installCustomAssets",
在标准 installAssets
调用之后。示例
{ "scripts": { "post-root-package-install": [ "SymfonyStandard\\Composer::hookRootPackageInstall" ], "symfony-scripts": [ "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", "Linkin\\Bundle\\CustomAssetsBundle\\Composer\\ScriptHandler::installCustomAssets", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget" ], "post-install-cmd": [ "@symfony-scripts" ], "post-update-cmd": [ "@symfony-scripts" ] } }
配置
要开始使用此包,您需要在全局项目配置 app/config/config.yml
中创建配置或在您的项目中的任何包中注册 custom_assets.yml
配置。简单的配置,应传输 Bootstrap
资源
linkin_custom_assets: sources: bootstrap_dir: '../vendor/twbs/bootstrap/dist'
有关配置和配置文件的更多信息,请参阅配置描述部分。
用法
使用示例预期使用前一部分中的简单配置。运行 custom_assets:install 命令后,从文件夹 vendor/twbs/bootstrap/dist
的资源将被传输到您的项目公共文件夹,并从 web/custom_assets/bootstrap_dir
可用。
因此,您可以访问所需的文件,例如 bootstrap.min.css
<link type="text/css" rel="stylesheet" href="{{ asset('custom_assets/bootstrap_dir/css/bootstrap.min.css') }}">
命令
- custom_assets:install - 根据创建的配置安装资源。