craftsnippets/static-file-manager
Composer 安装命令:
composer require craftsnippets/static-file-manager
包简介
Keep your static files list in PHP configuration file.
README 文档
README
Requirements
This plugin requires Craft CMS 3.0.0-beta.23 or later.
Installation
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project -
Then tell Composer to load the plugin:
composer require craftsnippets/static-file-manager -
In the Control Panel, go to Settings → Plugins and click the “Install” button for asset manifest.
Overview
- This plugin allows you to keep the list of CSS, JS and Favicon files in PHP configuration file instead of Twig templates.
- You can inject files from config file into frontend site and into control panel.
CSS and JS files will be injected into proper places - CSS files to end of
<head>and JS files at end of<body>. - You can also include links to google fonts CSS files, like
https://fonts.googleapis.com/css2?family=Montserrat:wght@100;400&display=swap- it will be included like other CSS files. - Plugin also allows for cache busting of files by appending URL parameter to their paths which contains their modification date. This means that files will be cache busted only if they were modified. Files from external servers won't be cache busted.
- Plugin exposes endpoint that lists all static files in JSON format, so the list can be consumed by frontend build tools. This does not include google fonts files.
Usage
In order to use plugin, place this code into base template of your project. Remember that static files won't be inserted is there is no <body> or <head> tags in your template.
{% do craft.staticFileManager.outputFiles() %}
You can pass variable set to false to this function to cancel injection of assets into template:
{% do craft.staticFileManager.outputFiles(false) %}
Files list to inject is set in config/static-file-manager.php setting file, under filesList setting. To inject files into control panel, place them into cpFileList setting. All file paths are relative to the web root.
Here is example config file:
<?php
return [
'filesList' => [
'some-file.css',
'other-file.js',
],
'cpFileList' => [
'some-control-panel-styles.css',
],
'faviconPath' => 'some-favicon.png',
'cpFaviconPath' => 'some-control-panel-favicon.png',
];
You can use inline php function to dynamically define injected file name:
<?php
return [
'filesList' => [
function(){
$language = Craft::$app->getSites()->currentSite->language;
if($language == 'en'){
return 'english-file.js';
}else{
return 'non-english-file.js';
}
}
]
];
Twig filter
You can manually bust cache of files within Twig templates using version filter:
<script src="{{'some_script.js'|version}}"></script>
JSON endpoint
Plugin exposes endpoint that returns asset list in JSON format. The list consists of two arrays - array with key css contains CSS files and array with key js contains Javascript files. Only files present on the filesystem are listed, so these from external servers are omitted from this list. List is available under [website url]/actions/static-file-manager URL, but you first need to enable it using exposeJsonList config setting.
Here's an example gulp task that loads list of Javascript files from endpoint and minifies them into one file. This config assumes that you use xampp and your project lives in htdocs directory.
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
const https = require('http');
gulp.task('production', ['sass:production', 'uglify:production']);
gulp.task('uglify:production', function() {
// set endpoint url
let file_path = __dirname;
let explode = file_path.split('htdocs');
let url = 'http://localhost'+explode[1]+'/web/actions/static-file-manager';
// load data
https.get(url,(res) => {
let body = "";
res.on("data", (chunk) => {
body += chunk;
});
res.on("end", () => {
let json = JSON.parse(body);
let js = json['js'];
// gulp task
return gulp.src(js)
.pipe(concat('main.min.js'))
.pipe(uglify())
.on('error', swallowError)
.pipe(gulp.dest('web/static'));
});
});
});
Settings
Place these settings in config/static-file-manager.php file.
filesList- array with list of static files paths within web root directory (usuallywebdirectory). These files will be injected into frontend site.cpFileList- array with list of static files within web root directory that will be injected into control panel.faviconPath- path to favicon file.cpFaviconPath- path to control panel favicon file.bustCache- if files should be cache busted. Default:true.exposeJsonList- if plugin should expose list of files in JSON format. Default:false.
Brought to you by Piotr Pogorzelski
craftsnippets/static-file-manager 适用场景与选型建议
craftsnippets/static-file-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 303 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 12 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cms」 「Craft」 「craftcms」 「craft-plugin」 「static file manager」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 craftsnippets/static-file-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 craftsnippets/static-file-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 craftsnippets/static-file-manager 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Expand, collapse, change the status of, or delete multiple blocks in a Matrix field simultaneously.
GraphQL authentication for your headless Craft CMS applications.
Set Links with a specific language parameter
Supercharged text field validation.
Integrate with Snipcart.
Restrict user registration by domain in Craft CMS, allows you to limit who can register for your site based on their email address.
统计信息
- 总下载量: 303
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-15