承接 tormjens/extended-mix 相关项目开发

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

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

tormjens/extended-mix

Composer 安装命令:

composer require tormjens/extended-mix

包简介

Extended version of the Laravel Mix helper.

README 文档

README

Extended Mix was born in an application that was entirely modular. We needed to load assets from our modules (Composer packages) while also making it possible to hot reload and host assets on a CDN.

This application had modules that were regular Composer packages, so the folder structure would be like.

app/
vendor/
    foo/
        bar/

When pushing to master it was setup to compile assets and push them up to AWS S3, which had a Cloudfront set up.

Locally we wanted to still be able to use HMR (hot reloading) or just compiling the assets to test.

In production we wanted assets to be found via our CDN.

Installation

Grab the package via Composer

composer require tormjens/extended-mix

This package does not have auto-discovery enabled as the application it is built for loads it and modifies the config for it at runtime. To enable the package you either have to register it via your config/app.php or within a serviceprovider loaded in your "main module".

This example is taken out of the core module of my application.

public function register()
{
    $this->app->register(MixServiceProvider::class);
    
    config([
        'mix.driver.cdn' => [
            'include_vendor' => env('MIX_CDN_INCLUDE_VENDOR', false),
            'url' => env('MIX_CDN_URL', 'https://cdn.foo.com'),
            'format' => env('MIX_CDN_FORMAT', '{url}/{package}/{version}/{path}'),
            'develop_cache_minutes' => env('MIX_CDN_DEVELOP_CACHE_MINUTES', 30),
        ]
    ]);
}

Getting the URL of an asset

It is actually very simple. Wherever you need the URL to an asset you'll simply use:

extendedMix('/css/app.css', 'foo/bar');

Behind the scenes this will pipe the requested file through a series of resolvers to figure out the URL:

  1. It will check to see if the requested file can be requested via hot reloading (very neat locally), and then return the URL to the file with hot reloading enabled.
  2. It will check whether there's a local copy of the file and the return the URL to a proxied asset.
  3. It will check the CDN (if configured), and return the URL.

Also, it does support mix-manifest so you can version your assets.

For cases where some assets are in the manifest, and some not (when you've used the copymethod), you can use the variableAsset function which will look for the asset locally first, then fallback to the CDN.

variableAsset('/images/someImage.png', 'foo/bar');

Proxied local assets

This package provides a convenient way of proxying assets stored locally via a route named mix.show. While this is very neat when testing locally, it is not ideal for production as it bootstraps the entire application just to serve a asset. You should consider adding a rule in your webserver that mimmicks this functionality.

CDN Assets

CDN is supported out of the box, but a convention is necessary to correctly display your assets. By default, we use the format /{vendor}/{package}/{version}/{pathToAsset} to append to your CDN url. That'll mean if your CDN domain is set to https://cdn.foo.com and you want to show get /css/app.css for the foo/bar package, which is installed with version 5.0, you will end up with: https://cdn.foo.com/foo/bar/5.0/css/app.css.

The format may be changed via the mix.driver.cdn.format config option. So if you wanted to omit the vendor you could set this to:

// config/mix.php
return [
    'driver' => [
        'cdn' => [
            'format' => '{url}/{package}/{version}/{path}'
        ]
    ]   
];

Then it will read the URL as https://cdn.foo.com/bar/5.0/css/app.css.

tormjens/extended-mix 适用场景与选型建议

tormjens/extended-mix 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.11k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 10 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 tormjens/extended-mix 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-10-06