samuell/cdn-plugin
Composer 安装命令:
composer require samuell/cdn-plugin
包简介
Push, sync, clear and serve assets to/from a CDN or include manifest files from webpack or laravel-mix.
关键字:
README 文档
README
Push, sync, clear and serve assets to/from a CDN or use it for including manifest files from webpack or laravel-mix.
https://octobercms.com/plugin/samuell-cdn
Usage
In your theme change asset links to use asset_cdn function.
Example:
<link rel="stylesheet" href="{{ asset_cdn('assets/css/app.css') }}"> <script src="{{ asset_cdn('assets/js/app.js') }}"></script>
Note: If you doesn't want to use CDN you can disable cdn in config and it will automatically fallback to theme path and use files from theme. (This is default configuration)
With manifest integration enabled:
We define file name that is compiled from Webpack or LaravelMix and exists in manifest.json file. Don't forget to enabled manifest integration and define correct manifest.json path in config file.
<link rel="stylesheet" href="{{ asset_cdn('app.css') }}">
Getting assets from cdn that are not in manifest.json file use cdn function with full path to file:
<link rel="stylesheet" href="{{ cdn('assets/css/app.css') }}">
After configuration (configuration steps are below) we can sync theme assets to cdn
Depending on theme run command to sync specific theme. For example to sync theme with name demo we use php artisan cdn:sync demo. If you want to remove old files that are compared with your local copy you can use flag --delete-old
Configuration
1. Configure Filesystem
If is your plan to use CDN, you can use this config. If not you can skip this step. Example is for AWS S3 with Cloudfront.
config/filesystems.php
'asset-cdn' => [ 'driver' => 's3', 'key' => env('S3_KEY'), 'secret' => env('S3_SECRET'), 'region' => env('S3_REGION'), 'bucket' => env('S3_BUCKET'), 'root' => 'assets/', ],
2. Configure config
Create cdn.php file in config folder to configure cdn plugin, this allows to use different configs for developing or local enviroments.
Don't forget to define root filesystem folder same as assetsFolder best is to use default as assets to match october default theme assets folder.
config/cdn.php
return [ // CDN integration 'active' => false, 'url' => 'https://cdn.mydomain.com/', 'assetsFolder' => '/assets/', // Manifest integration (webpack, laravel mix) 'useManifest' => false, 'manifestPath' => '/assets/compiled/manifest.json', // Filesystem information that will be used with sync, push, clear commands 'filesystem' => [ 'disk' => 'asset-cdn', 'options' => [] ] // Files filter 'files' => [ 'ignoreDotFiles' => true, 'ignoreVCS' => true, 'include' => [ 'paths' => [ // ], 'files' => [ // ], 'extensions' => [ // ], 'patterns' => [ // ], ], 'exclude' => [ 'paths' => [ // ], 'files' => [ // ], 'extensions' => [ // ], 'patterns' => [ // ], ], ], ];
Optional filesystem options:
Filesystem allows to define custom options. The following example is recommended for AWS S3.
cdn.php > filesystem.options
'options' => [ 'ACL' => 'public-read', 'CacheControl' => 'max-age=31536000, public' ]
Commands
Sync Assets
Sync all assets but deletes old files that are on CDN.
php artisan cdn:sync {theme} {--delete-old}
- delete-old option enables automatic deletion of old files that does not exist in local folder
Push Assets
Pushes assets but does not delete old files on CDN.
php artisan cdn:push {theme}
Delete all assets from CDN
Deletes all assets from CDN.
php artisan cdn:clear {theme}
Twig Functions
- Replace
'path'|themewithasset_cdn('path')(It can read manifest.json file if option useManifest is set to true in config). - Replace any asset that is going out of asset theme directory or is not used in manifest with
cdn('path').
Inspired by AsssetCDN package for Laravel https://github.com/arubacao/asset-cdn
samuell/cdn-plugin 适用场景与选型建议
samuell/cdn-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 323 次下载、GitHub Stars 达 6, 最近一次更新时间为 2019 年 08 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sync」 「cdn」 「manifest」 「octobercms」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 samuell/cdn-plugin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 samuell/cdn-plugin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 samuell/cdn-plugin 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Plugin Manifest is the conduit between Craft CMS plugins and webpack, with manifest.json & webpack-dev-server HMR support
Injects assets from a Vite manifest to the Wordpress head, supports themes and plugins
A sleek PHP wrapper around rclone with Laravel-style fluent API syntax
Package to use WebpackManifestPlugin in laravel
Sync content to other sites on element save.
PWA manifest and Blade directives for Laravel.
统计信息
- 总下载量: 323
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-08-19