定制 elephfront/robo-js-minify 二次开发

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

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

elephfront/robo-js-minify

Composer 安装命令:

composer require elephfront/robo-js-minify

包简介

Robo task to perform minification on your JS files.

README 文档

README

Software License Build Status Codecov

This Robo task performs a minification of your JS content.

This task performs the minification using matthiasmullie/minify library.

Requirements

  • PHP >= 7.1.0
  • Robo

Installation

You can install this Robo task using composer.

The recommended way to install composer packages is:

composer require elephfront/robo-js-minify

Using the task

You can load the task in your RoboFile using the LoadJsMinifyTasksTrait trait:

use Elephfront\RoboJsMinify\Task\Loader\LoadJsMinifyTasksTrait;

class RoboFile extends Tasks
{

    use LoadJsMinifyTasksTrait;
    
    public function minifyJs()
    {
        $this
            ->taskJsMinify([
                'assets/js/main.js' => 'assets/min/js/main.min.js',
                'assets/js/home.js' => 'assets/min/js/home.min.js',
            ])
            ->run();
    }
}

The only argument the taskJsMinify() takes is an array ($destinationsMap) which maps the source files to the destination files : it will load the assets/js/main.js, do its magic and put the final content in assets/min/js/main.min.js and do the same for all of the other files.

GZIP compression

In addition to minifying your files, you can gzip them. You can enable gzip using the enableGzip() method :

    $this
        ->taskJsMinify([
            'assets/js/main.js' => 'assets/min/js/main.min.js',
            'assets/js/home.js' => 'assets/min/js/home.min.js',
        ])
        ->enableGzip()
        ->run();

By default, files will be compressed using the maximum level (which is 9). You can customize the compression level using the method setGzipLevel() :

    $this
        ->taskJsMinify([
            'assets/js/main.js' => 'assets/min/js/main.min.js',
            'assets/js/home.js' => 'assets/min/js/home.min.js',
        ])
        ->enableGzip()
        ->setGzipLevel(5)
        ->run();

The setGzipLevel accepts values from -1 to 9. If you use -1, the default compression level of the zlib library will be used. 0 means you do not want any compression and 9 is the maximum level of compression. If you use a value that is out of these bounds, the maximum compression level will be used.

Chained State support

Robo includes a concept called the Chained State that allows tasks that need to work together to be executed in a sequence and pass the state of the execution of a task to the next one. For instance, if you are managing assets files, you will have a task that compile SCSS to CSS then another one that minify the results. The first task can pass the state of its work to the next one, without having to call both methods in a separate sequence.

The robo-js-minify task is compatible with this feature.

All you need to do is make the previous task return the content the robo-js-minify task should operate on using the data argument of a Robo\Result::success() or Robo\Result::error() call. The passed data should have the following format:

$data = [
    'path/to/source/file' => [
        'js' => '// Some JS code',
        'destination' => 'path/to/destination/file
    ]
];

In turn, when the robo-js-minify task is done, it will pass the results of its work to the next task following the same format.

Preventing the results from being written

By default, the robo-js-minify task writes the result of its work into the destination file(s) passed in the $destinationsMap argument. If the robo-js-minify task is not the last one in the sequence, you can disable the file writing using the disableWriteFile() method. The files will be processed but the results will not be persisted and only passed to the response :

$this
    ->taskJsMinify([
        'assets/js/main.js' => 'assets/min/js/main.min.js',
        'assets/js/home.js' => 'assets/min/js/home.min.js',
    ])
        ->disableWriteFile()
    ->someOtherTask()
    ->run();

Contributing

If you find a bug or would like to ask for a feature, please use the GitHub issue tracker. If you would like to submit a fix or a feature, please fork the repository and submit a pull request.

Coding standards

This repository follows the PSR-2 standard.

License

Copyright (c) 2017, Yves Piquel and licensed under The MIT License. Please refer to the LICENSE.txt file.

elephfront/robo-js-minify 适用场景与选型建议

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

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

围绕 elephfront/robo-js-minify 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-13