solo/assets

用于组合和压缩 Solo 框架中的 JavaScript 和 CSS 文件的组件

1.0.2 2015-10-15 09:05 UTC

This package is auto-updated.

Last update: 2024-09-14 22:39:03 UTC


README

实现具有组合和压缩功能的 JavaScript 文件发布

安装

通过 composer 安装

"require": {
	"solo/assets": ">=1"
}

配置

该组件具有适配器,可以将其作为 ApplicationComponent 连接到项目中

在 common.php 文件中添加

"components" => array(
	"solo_assets" => array
    (
        "@class" => "Solo\\Web\\Assets\\SoloAdapter",
        "ttl" => 86400,
        "debug" => true,
        "async" => false,
        "outdir" => "/assets"
    ),
)

然后在模板处理器设置中连接扩展(例如,Smarty 函数)

"controller" => array(
	....
	"options" => array(
		....
		"plugins" => array('"Solo\\Web\\Assets\\Smarty\\Assets")
	)
)

选项

  • files - 文件列表,通过逗号分隔的资源文件
  • async - 是否需要在生成的 script 标签中添加 async 属性(仅当 debug=false 时)
  • debug - 调试模式,如果 TRUE - 分别连接所有文件,如果 FALSE - 将所有文件合并为一个。默认为 TRUE
  • ttl - 秒,文件变更检查的时间间隔(如果为 0 - 则在每次请求时检查)
  • outdir - 包含编译文件的目录路径。必须作为公共目录在服务器上可用。默认为 /assets。
  • documentRootDir - 位于 web 服务器控制下的目录路径。outdir 相对于它确定。默认为 $_SERVER["DOCUMENT_ROOT"] 注意!必须对 outdir 目录具有写入权限

示例

建议使用 Smarty 函数

index.html

{assets files='/js/common.js,/js/another.js' ttl=10 outdir='/assetsDir' debug=true async=false}

debug、async、ttl 和 outdir 参数是可选的,但如果已设置,则优先于配置文件中的设置。