定制 lapaz/amechan 二次开发

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

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

lapaz/amechan

Composer 安装命令:

composer require lapaz/amechan

包简介

Lightweight Pre-processed Asset Link Manager

README 文档

README

Build Status

Amechan (means candy drop in Osaka, Japan) is a lightweight pre-processed asset link manager for PHP. This library has no side effects unlike Assetic, Sprockets Rails or such as, instead it works better with NodeJS tools like Gulp.

Quick Start

Define named asset which bundles JS or CSS contents:

$assetManager = new AssetManager();

$assetManagr->asset('jquery', [
    'file' => '/assets/vendor/jquery/dist/jquery.js',
    'section' => 'js',
]);
$assetManagr->asset('bootstrap', [
    'baseUrl' => '/assets/vendor/bootstrap/dist',
    'bundles' => [
        [
            'files' => ['css/bootstrap.css', 'css/bootstrap-theme.css'],
            'section' => 'css',
        ],
        [
            'file' => 'js/bootstrap.js',
            'section' => 'js',
        ],
    ],
    'dependency' => 'jquery',
]);
$assetManagr->asset('some-jquery-plugin', [ ... ]);
$assetManagr->asset('and-another-one', [ ... ]);

Prepare asset collection for presentation session before rendering.

$assets = $assetManagr->newCollection();

In your view file, require assets:

layout.php

<?php
$assets->add('bootstrap');
?>
<!DOCTYPE html>
<html>
<head>
... layout here

app-view.php

<?php
$assets->add('bootstrap');
$assets->add('some-jquery-plugin');
?>
<div id="app-view">
    ... app html
</div>

Redundant ->add() calls are summarized and they are ordered by its dependencies.

Then, in head or end of body tags (often included in the layout template):

<?php
foreach ($assets->collectUrls('css') as $url) {
    echo "<link href="{$url}" rel="stylesheet">\n";
}
?>
</head>
<?php
foreach ($assets->collectUrls('js') as $url) {
    echo "<script src="{$url}"></script>\n";
}
?>
</body>

All required assets are collected and expanded there.

<link href="/assets/vendor/bootstrap/dist/css/bootstrap.css" rel="stylesheet">
<link href="/assets/vendor/bootstrap/dist/css/bootstrap-theme.css" rel="stylesheet">
</head>
<body>
    :
    :
<script src="/assets/vendor/jquery/dist/jquery.js"></script>
<script src="/assets/vendor/bootstrap/dist/js/bootstrap.js"></script>
<script src="/assets/js/some-jquery-plugin.js"></script>
</body>

Features

  • Bundling multi sectioned assets as single unit
  • Link order auto detection according to dependency chain
  • Source to built URL mapping (any to *.min.js)
  • Revision hash support with rev-manifest.json format

URLs can be mapped when compiled version assets exist.

if (is_dir(__DIR__ . '/../public/assets/dist')) {
    $assetManager->mapping(new UnifiedResourceMapper('/assets', [
        'dist/css/all.min.css' => [
            'vendor/bootstrap/dist/css/bootstrap.css',
            'vendor/bootstrap/dist/css/bootstrap-theme.css',
        ],
        'dist/js/all.min.js' => [
            'vendor/jquery/dist/jquery.js',
            'vendor/bootstrap/dist/js/bootstrap.js',
        ],
    ]));
}
<link href="/assets/dist/css/all.min.css" rel="stylesheet">

<script src="/assets/dist/js/all.min.js"></script>

URLs can be replaced to revision hashed version.

if (is_file(__DIR__ . '/../public/assets/dist/rev-manifest.json')) {
    $manifest = json_decode(file_get_contents(
        __DIR__ . '/../public/assets/dist/rev-manifest.json'
    ), true);
    $assetManager->mapping(new RevisionHashMapper('/assets/dist/', $manifest));
}
<link href="/assets/dist/css/all-33f4c35457.min.css" rel="stylesheet">

<script src="/assets/dist/js/all-5d8020ef9b.min.js"></script>

Definition

// TBD (See /example project)

lapaz/amechan 适用场景与选型建议

lapaz/amechan 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.56k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 05 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 lapaz/amechan 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 lapaz/amechan 我们能提供哪些服务?
定制开发 / 二次开发

基于 lapaz/amechan 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-05-15