blackcube/yii-assets
Composer 安装命令:
composer require blackcube/yii-assets
包简介
Vite and Webpack asset bundles for Yii with scaffolding command
README 文档
README
Vite and Webpack asset bundles for Yii with manifest support.
Installation
composer require blackcube/yii-assets
Configuration
Aliases
In config/web/aliases.php, ensure these aliases are defined:
<?php declare(strict_types=1); return [ '@assets' => '@root/www/assets', '@assetsUrl' => '@baseUrl/assets', '@assetsSource' => '@root/assets', '@baseUrl' => '/', '@public' => '@root/www', ];
| Alias | Used by | Purpose |
|---|---|---|
@assets |
$basePath |
Where Yii publishes assets (copy/symlink) |
@assetsUrl |
$baseUrl |
Public URL to access published assets |
@assetsSource |
$sourcePath |
Path to build output (optional shortcut) |
DI Container
Create config/web/di/assets.php:
<?php declare(strict_types=1); use Blackcube\Assets\ManifestAssetLoader; use Yiisoft\Aliases\Aliases; use Yiisoft\Assets\AssetLoader; use Yiisoft\Assets\AssetLoaderInterface; use Yiisoft\Definitions\Reference; return [ AssetLoaderInterface::class => [ 'class' => ManifestAssetLoader::class, '__construct()' => [ 'innerLoader' => Reference::to(AssetLoader::class), 'aliases' => Reference::to(Aliases::class), ], ], ];
Quick Start
1. Initialize build tools (once)
./yii blackcube:assets/init
Interactive prompts:
- Builder(s):
vite,webpack, orboth - Source directory (default:
assets/src) - Output base directory (default:
assets)
Generated files:
project/
├── assets-blackcube.json
├── package.json
├── tsconfig.json
├── vite.config.mts # if Vite selected
├── vite-manifest-plugin.mts # if Vite selected
├── webpack.config.mts # if Webpack selected
└── assets/
└── src/
└── tsconfig.json
2. Build
npm install npm run dist-clean
Output structure:
assets/
├── dist-vite/
│ ├── js/
│ ├── css/
│ └── assets-catalog.json
└── dist-webpack/
├── js/
├── css/
└── assets-catalog.json
3. Create your asset bundle(s)
Create one or more bundles pointing to the build output:
Vite:
<?php declare(strict_types=1); namespace App\Asset; use Blackcube\Assets\ViteAssetBundle; final class AppAsset extends ViteAssetBundle { public ?string $basePath = '@assets'; public ?string $baseUrl = '@assetsUrl'; public ?string $sourcePath = '@assetsSource/dist-vite'; }
Webpack:
<?php declare(strict_types=1); namespace App\Asset; use Blackcube\Assets\WebpackAssetBundle; final class AppAsset extends WebpackAssetBundle { public ?string $basePath = '@assets'; public ?string $baseUrl = '@assetsUrl'; public ?string $sourcePath = '@assetsSource/dist-webpack'; }
4. Register in view
$assetManager->register(AppAsset::class);
npm Scripts
| Script | Description |
|---|---|
npm run dist-clean |
Build all (Vite + Webpack) |
npm run dist-clean-vite |
Build Vite only |
npm run dist-clean-webpack |
Build Webpack only |
npm run watch |
Webpack dev mode with watch |
Advanced Options
WebpackAssetBundle
final class AppAsset extends WebpackAssetBundle { public ?string $basePath = '@assets'; public ?string $baseUrl = '@assetsUrl'; public ?string $sourcePath = '@assetsSource/dist-webpack'; // Explicit bundle order (default: auto-detect from catalog) public array $bundles = ['manifest', 'vendors', 'app']; // Load only CSS from these bundles (skip JS) public array $cssOnly = []; // Load only JS from these bundles (skip CSS) public array $jsOnly = ['manifest']; }
By default, WebpackAssetBundle auto-loads all bundles from the catalog with ordering: manifest → vendors → rest.
License
BSD-3-Clause. See LICENSE.md.
Author
Philippe Gaultier philippe@blackcube.io
blackcube/yii-assets 适用场景与选型建议
blackcube/yii-assets 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 125 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「assets」 「yii」 「manifest」 「webpack」 「vite」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 blackcube/yii-assets 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 blackcube/yii-assets 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 blackcube/yii-assets 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Plugin Manifest is the conduit between Craft CMS plugins and webpack, with manifest.json & webpack-dev-server HMR support
Asset Management for PHP
Caching and compression for Twig assets (JavaScript and CSS).
Injects assets from a Vite manifest to the Wordpress head, supports themes and plugins
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Package to use WebpackManifestPlugin in laravel
统计信息
- 总下载量: 125
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 28
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2026-01-24