承接 clancats/packtacular 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

clancats/packtacular

Composer 安装命令:

composer require clancats/packtacular

包简介

Packtacular is a simple and fast asset packer and compressor.

README 文档

README

Packtacular is a fast and easy asset packer, compressor, manager.

We are all busy so we should not waste time dealing with asset packing. Im also going to skip all the "where the idea came from bla bla" so lets directly continue with how to use Packtacular.

don't forget that you need to grant write permission's for php.

Usage

First of all packtacular need's to know where your storage directory ( public directory ) is. If you don't set up the storage directory packtacular is going to use the relative path.

Packtacular::storage( $_SERVER['DOCUMENT_ROOT'].'/' );

The thing here was "Hey let's keep it easy" so to create your package you only need to do this:

Packtacular::<type>( '<source>', '<target>' );

Example:

// When you pass relative paths packtacular is going to prefix your path
// with the storage directory. `<storage>/assets/css/`
Packtacular::css( 'assets/css/', 'cache/stylesheet_:time.css' )

This example will return an absolute public path to the package assuming that the target is the public root path. /cache/stylesheet_1395407386.css

A bit more detail

Packtacular::<filetype>( <dir>|<files_array>, <target_file> );

Type: This means the basically the file extension. Packtacular::js will match all .js files in the given directory.

Source: I hope this is not to confusing. If you set a folder as source Packtacular is going to search in that directory for all files matching the given type. Alternatively you can pass an array of files.

Target: Define where the cache file should be created. You can simply pass a file path. To bypass the problem that the browser might cache the files on its own, you can add a timestamp to the path using the :time parameter.

Example with a fixed array

Packtacular::js( array(
	'js/jquery.js',
	'js/myscript.js',
), 'cache/:time/core.js' );

Filters

Filters can catch the file contents before they get packed. Wich gives you the possibility to compress or compile your assets.

Packtacular::filter( '<type>', function( $data ) 
{	
	// do something with $data
	return $data;
});

There are 2 types of filters package and single file filter.

The single filter will be applied over every file on it's own.

// This little example will add a comment above each file 
// containing the file path of the current file.
Packtacular::filter( '*', function( $data, $file_name ) 
{	
	return "/* ".$file_name." */\n".$buffer;
}, true );

The normal filter can only modify the entire package.

// This little example will only be executed on the entire package.
Packtacular::filter( 'css', function( $data ) 
{	
	return str_replace( ' ', '', $data );
});

Preset filters

There are some filter that already ship with packtacular you can add them by simply executing:

Packtacular_Filter::add( 'comments' );

Following filters are available:

  • comments

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-03-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固