定制 tleckie/versioned-assets 二次开发

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

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

tleckie/versioned-assets

Composer 安装命令:

composer require tleckie/versioned-assets

包简介

Moving asset locations is cumbersome and error prone it requires you to carefully update the URLs of all assets included in all templates. The asset component allows you to have full control of the paths of your resources in an orderly way that is easy to maintain.

README 文档

README

Fast and powerful php versioned-assets engine

Scrutinizer Code Quality Code Intelligence Status Build Status

Installation

You can install the package via composer:

composer require tleckie/versioned-assets

Moving asset locations is cumbersome and error, prone - it requires you to carefully update the URLs of all assets included in all templates. The asset component allows you to have full control of the paths of your resources in an orderly way that is easy to maintain.

Usage

<?php

use Tleckie\Assets\Bucket;
use Tleckie\Assets\Versioned\Versioned;

$bucket = new Bucket(new Versioned('v1'), '/path');

// Relative path
$bucket->url('js/app.js');
//result: /path/js/app.js?v1

// Absolute path
$bucket->url('/js/app.js');
//result: /js/app.js?v1

You can also customize the format of your version by adding the second parameter to which a sprintf will be applied:

<?php

use Tleckie\Assets\Bucket;
use Tleckie\Assets\Versioned\Versioned;

$bucket = new Bucket(
    new Versioned('v1', "%s?custom-version=%s"), 
    '/path'
);

// Relative path
$bucket->url('js/app.js');
//result: /path/js/app.js?custom-version=v1

// Absolute path
$bucket->url('/js/app.js');
//result: /js/app.js?custom-version=v1

If you need to include your assets to have a domain, you simply need to include the domain as the value of the path argument: When configuring a domain as a path, the resources included as relative and absolute will have the same result

<?php

use Tleckie\Assets\Bucket;
use Tleckie\Assets\Versioned\Versioned;

$bucket = new Bucket(
    new Versioned('v1', '%s?version=%s'), 
    '//domain.cookieless.com'
);

// Relative path
$bucket->url('js/app.js');
//result: //domain.cookieless.com/js/app.js?version=v1

// Absolute path
$bucket->url('/js/app.js');
//result: //domain.cookieless.com/js/app.js?version=v1
<?php

use Tleckie\Assets\Bucket;
use Tleckie\Assets\Versioned\Versioned;

$bucket = new Bucket(
    new Versioned('v1', '%2$s/%1$s'), 
    '//domain.cookieless.com'
);

// Version in path
$bucket->url('js/app.js');
//result: //domain.cookieless.com/v1/js/app.js

You can also use NullVersioned if you want to disable versioning for your assets.

<?php

use Tleckie\Assets\Bucket;
use Tleckie\Assets\Versioned\NullVersioned;

$bucket = new Bucket(
    new NullVersioned(), 
    '//domain.cookieless.com'
);

// Relative path
$bucket->url('js/app.js');
//result: //domain.cookieless.com/js/app.js

A popular strategy to manage asset versioning, which is used by tools such as Webpack, is to generate a JSON file mapping all source file names to their corresponding output file:

{
"css/app.css": "build/css/app.af316426ea1d10021f3f17ce8031f93c2.css",
"js/app.js": "build/js/app.56fa630905267b809161e71d0f8a0c017b.js"
}
<?php

use Tleckie\Assets\Bucket;
use Tleckie\Assets\Versioned\JsonManifestVersioned;
$bucket = new Bucket(
    new JsonManifestVersioned(__DIR__ .'/json/rev-manifest.json')
);

$bucket->url('css/app.css');
//result: build/css/app.af316426ea1d10021f3f17ce8031f93c2.css

$bucket->url('js/app.js');
//result: build/js/app.56fa630905267b809161e71d0f8a0c017b.js
<?php

use Tleckie\Assets\Bucket;
use Tleckie\Assets\Versioned\JsonManifestVersioned;

$bucket = new Bucket(
    new JsonManifestVersioned(__DIR__ .'/json/rev-manifest.json'),
    '//domain.cookieless.com'
);

$bucket->url('css/app.css');
//result: //domain.cookieless.com/build/css/app.af316426ea1d10021f3f17ce8031f93c2.css

$bucket->url('js/app.js');
//result: //domain.cookieless.com/build/js/app.56fa630905267b809161e71d0f8a0c017b.js

Custom versioning:

You can create your custom versioning class by implementing the VersionedInterface interface.

That's all! I hope this helps you ;)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-05-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固