定制 scafera/asset 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

scafera/asset

最新稳定版本:v1.0.2

Composer 安装命令:

composer require scafera/asset

包简介

Asset management for the Scafera framework

README 文档

README

Asset management for the Scafera framework. Configures Symfony's AssetMapper internally — your code references assets via asset() in Twig templates, never through PHP imports.

Provides: Asset management for Scafera — configures Symfony's AssetMapper internally; projects reference assets via Twig's asset() function, never PHP imports. Companion bundles (e.g. TailwindBundle) auto-register when installed.

Depends on: A Scafera host project with scafera/frontend installed (for Twig's asset() function) and an assets/ directory at the project root.

Extension points: None of its own — AssetMapper is configured internally. Extra asset paths via framework.asset_mapper.paths in config/config.yaml. Ecosystem integrations (e.g. TailwindBundle) auto-register via the kernel's extra.scafera-bundles mechanism.

Not responsible for: Template rendering (owned by scafera/frontend) · JavaScript bundling (AssetMapper uses native ES modules) · Node.js tooling (TailwindBundle manages its own standalone binary) · folder conventions (owned by architecture packages).

This is a capability package (adoption gate). It adds optional asset support to a Scafera project. It does not define folder structure or architectural rules — those belong to architecture packages.

Installation

composer require scafera/asset

The bundle is auto-discovered via Scafera's symfony-bundle type detection. No manual registration needed.

Requirements

  • PHP 8.4+
  • scafera/kernel ^1.0
  • scafera/frontend (for template rendering with asset())

Usage

Referencing assets in templates

Place CSS, JS, and other static files in assets/ at your project root. Reference them in Twig templates using the asset() function:

<link rel="stylesheet" href="{{ asset('styles/app.css') }}">
<script src="{{ asset('js/app.js') }}"></script>
<img src="{{ asset('images/logo.png') }}">

Using with Tailwind CSS

Install the TailwindBundle — it is auto-registered as a companion bundle:

composer require symfonycasts/tailwind-bundle

Initialize and build:

vendor/bin/scafera symfony tailwind:init
vendor/bin/scafera symfony tailwind:build

For development with auto-rebuild on file changes:

vendor/bin/scafera symfony tailwind:build --watch

Reference the compiled CSS in your template:

<link rel="stylesheet" href="{{ asset('styles/app.css') }}">

Production deployment

Compile assets with versioned filenames for cache busting:

vendor/bin/scafera symfony asset-map:compile

This writes versioned files to public/assets/ for direct serving by the web server.

Companion Bundles

This package declares companion bundles via extra.scafera-bundles in its composer.json. When you install a companion package, Scafera registers its bundle automatically — no manual configuration needed.

Package Bundle Purpose
symfonycasts/tailwind-bundle SymfonycastsTailwindBundle Tailwind CSS compilation via standalone binary

Companions are only registered when installed. If you don't composer require the package, the declaration is ignored.

Boundary Enforcement

This package includes an AssetMapperLeakageValidator that scans your src/ directory for direct Symfony\Component\AssetMapper\* imports. Violations are reported by scafera validate:

Package checks:
  ✗ No AssetMapper imports in userland FAILED
    - src/Service/AssetHelper.php: imports AssetMapper types directly — use asset() in Twig templates instead

Use asset() in templates — don't import AssetMapper types in PHP.

Configuration

The bundle configures AssetMapper automatically:

  • Asset paths: assets/ at your project root
  • Public prefix: /assets/

To override defaults, add a framework: section to config/config.yaml:

framework:
    asset_mapper:
        paths:
            - 'assets/'
            - 'vendor/some-package/assets/'

License

MIT

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固