dansol/webpack-encore-view-helper
Composer 安装命令:
composer require dansol/webpack-encore-view-helper
包简介
Symfony webpack encore laminas view helper
README 文档
README
webpack-encore-view-helper is a laminas-view helper that help render all of the dynamic script and link tags needed when using Symfony Webpack Encore( a simpler way to integrate Webpack into your application - https://symfony.com/doc/current/frontend.html#webpack-encore).
Installation
Run the following to install:
$ composer require dansol/webpack-encore-view-helper
Documentation
Copy webpack_encore_view_helper_config.global.php.dist to config/autoload and rename webpack_encore_view_helper_config.global.php
Adjust configuration based on your enviroment.
example:
<?php return [ ... 'webpack_encore_view_helper_config'=>[ /* webpack encore entry points */ 'entrypoints_map' => json_decode(file_get_contents(__DIR__ . '/../../public/build/entrypoints.json'),true), /* map view to entrypoint ( array can be empty if templates name match entrypoint name when using auto* parameters */ 'template_entrypoint_map'=>[ 'layout::default'=>'app', ] ] ];
Load ConfigProvider in your configuration loader.
Mezzio example:
<?php $aggregator = new ConfigAggregator([ // ... other stuff \WebpackEncoreViewHelper\ConfigProvider::class, // Default App module config new PhpFileProvider(realpath(__DIR__) . '/autoload/{{,*.}global,{,*.}local}.php'), // Load development config if it exists new PhpFileProvider(realpath(__DIR__) . '/development.config.php'), ], $cacheConfig['config_cache_path']); ?>
Basic usage
... // load asset ( in layout template) $this->webpack_encore_assets('common entrypointname'); // if used a common entry // load asset ( in template that consume an entrypoint) $this->webpack_encore_assets('common entrypointname'); // if used a common entry // in layout template // render link tags echo $this->webpack_encore_assets()->render('css'); ... // render script tags echo $this->webpack_encore_assets()->render('js');
Special parameters
these parameters can be used in parent template(layout template) - if used in child template an error will be raise:
- auto - load all assets automatically( parent and first child template in content)
- auto-route - load all assets for parent template(layout)
- auto-child - load all assets for child template(firt template in layout content) this parameters avoid the need to load asset in every template that consume an entry point and load asset only in the main layout template
auto* parameters load entry with this logic: asset is loaded matching templatename/entrypoint name configured in webpack_encore_view_helper_config.global.php configuration file in template_entrypoint_map key ( see webpack_encore_view_helper_config.global.php.dist) if not matched the helper will try to match template name equal to entrypoint name. If entrypoint is not resolved an error will be raise.
basic example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <link rel="shortcut icon" href="https://getlaminas.org/images/favicon/favicon.ico" /> <?=$this->headTitle('mezzio')->setSeparator(' - ')->setAutoEscape(false)?> <?=$this->headMeta()?> <?php // load all asset for $this->webpack_encore_assets('auto'); ?> <?php // render links tags for this template(shared entry) and every asset required for the first child template in content echo $this->webpack_encore_assets()->render('css') ?> </head> <body class="app"> ... <div class="app-content"> <main class="container"> <?=$this->content?> </main> </div> <footer class="app-footer"> ... </footer> <?php // render scripts tags for this template(shared entry) and every asset required for the first child template in content echo $this->webpack_encore_assets()->render('js') ?> </body> </html>
dansol/webpack-encore-view-helper 适用场景与选型建议
dansol/webpack-encore-view-helper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 537 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 02 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「webpack」 「encore」 「laminas」 「laminas view helper」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dansol/webpack-encore-view-helper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dansol/webpack-encore-view-helper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dansol/webpack-encore-view-helper 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Webpack Manifest support
This package provide a Geo modules for yawik.
Dynamic Data Fields for Laravel
Package to use WebpackManifestPlugin in laravel
PSR-11 Aura.DI container configurator for Laminas and Mezzio applications. Drop-in replacement for the archived laminas/laminas-auradi-config with PHP 8.4 and 8.5 support.
Symfony's Webpack Encore for Laravel
统计信息
- 总下载量: 537
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-02-26