pjparra / assetic-smarty
Smarty 的 Assetic 插件
1.0.0
2017-05-13 11:51 UTC
Requires
- php: >=5.3.1
Suggests
- kriswallsmith/assetic: assetic-smarty provides the integration with Assetic.
- packagist/closurecompiler-bin: assetic-smarty provides the integration with Google closuer compiler.
- packagist/yuicompressor-bin: assetic-smarty provides the integration with yui compressor.
- smarty/smarty: assetic-smarty provides the integration with Smarty.
This package is not auto-updated.
Last update: 2024-09-28 15:59:53 UTC
README
使用此 Smarty 插件,Assetic 可以轻松集成到 Smarty 3 中。只需将此插件放入 Assetic/Extensions/Smarty 文件夹。
首先,您需要将 Assetic/Extension/Smarty 添加到您的 Smarty plugins_dir
$smarty = new Smarty(); // ... $smarty->plugins_dir[] = 'path/to/Assetic/Extension/Smarty';
简单使用示例
{assetic
assets="style/reset.css,style/common.css,style/other.css"
output="css"
config_path="config"
build_path="style/build"
debug=false
filters="yui_css,less"
asset_url=asset_url}
<link rel="stylesheet" href="{$asset_url}">
{/assetic}
以下是可能的参数列表
- assets:要包含在构建中的文件列表,以逗号分隔(可以是 CSS 或 JS 文件)
- bundle:捆绑名称。我们稍后将会讨论。与 "assets" 参数不兼容,您必须在这两个之间选择。
- output:您想要的输出类型,可以是 "css" 或 "js"
- config_path:插件将查找配置文件的文件夹(我们稍后将会讨论这些文件)
- build_path:插件将存储所有资产的单个文件夹
- debug:如果设置为 true,则插件不会合并您的资产,以便更容易进行调试
- filters:要应用的筛选器列表,以逗号分隔。目前仅支持 LESS 和 YuiCompressor(CSS 和 JS)
- asset_url:用于传递资产 URL 到 <link> 标签的变量名称
您需要提供 3 个外部文件
config.json
{
"yuicompressor_path": "/path/to/yuicompressor.jar",
"closurejar_path": "/path/to/google_closure/compiler.jar",
"cssembed_path": "/path/to/...",
"java_path": "/usr/bin/java"
}
根据您的偏好,您可以选择以下 2 个文件中的任意一个
bundles.json 允许您简单地指定要包含在捆绑中的文件
{
"css":
{
"main":
[
"css/reset.css",
"css/common.css",
"css/other.css"
]
}
}
此文件允许您在 "bundle" 参数中使用 "main" 捆绑名称,而不是仅将文件名列表提供给 "assets" 参数
dependencies.json 稍微复杂一些,但允许您利用 AssetReference Assetic 的功能。对 JS 资产非常有用
{
"js":
{
"references":
{
"awesomelib": "js/awesome.lib.js",
"anotherlib": "js/another.lib.js",
"somejs": "js/just.some.js.file.js"
},
"assets":
{
"js/foo.js": ["awesomelib","anotherlib"],
"js/bar.js": ["somejs"],
"js/no.dependencies.js": []
}
}
}
这允许您跟踪 JS 文件之间的依赖关系,这非常有用。然后,您只需在 "assets" 参数中指定您的 "有用" JS 文件的名称。插件将负责包括必要的依赖项,而不会出现重复。因此,如果您在 "assets" 参数中写入 "js/foo.js,js/no.dependencies.js",则插件将把 js/awesome.lib.js、js/another.lib.hs、js/foo.js 和 js/no.dependencies.js 合并到构建中。