malyusha/laravel-webpack-assets 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

malyusha/laravel-webpack-assets

Composer 安装命令:

composer require malyusha/laravel-webpack-assets

包简介

Package to use WebpackManifestPlugin in laravel

README 文档

README

Laravel Webpack Assets

Package that allows you to include assets from json file, generated by Webpack Manifest Plugin

Installation

Require the latest version of package using Composer

$ composer require malyusha/laravel-webpack-assets

If you are using version of laravel < 5.5, you need to add service provider into your config/app.php file in providers section:

  • \Malyusha\WebpackAssets\WebpackAssetsServiceProvider::class

You can add the WebpackAssets facade in facades section:

  • 'WebpackAssets' => \Malyusha\WebpackAssets\Facade::class

Configuration

To change package configuration you need to publish configuration file:

$ php artisan vendor:publish --tag=config

This will publish assets_manifest.php file inside your config directory. Configuration file has a few options:

  • file - path to manifest.json file, relative to disk path. See disk option;
  • fail_on_load - whether to fail on load assets file. If true - exception will be thrown;
  • disk - where your manifest.json and all assets file are located. See laravel config/filesystems.php -> disks.

Usage

Package provides helper functions to include script and style HTML elements inside blade templates:

  • webpack_script($script) - will generate <script src="path_to_script_from_manifest_file"></script>;
  • webpack_style($script- will do the same as webpack_script but for style;
  • webpack($chunkName = null) - will return instance of Asset class if no arguments provided, otherwise returns asset url with host.

Examples

Let's imagine, that you have generated manifest.json file with such content:

{
  "app.js": "/assets/1b53147322421b069bf1.js",
  "auth.background.png": "/assets/e60cc0de08eee2256222218425eaa943.png",
  "auth.login.css": "/assets/css/20a7e7e51e1f142b2b1f.css",
  "auth.login.js": "/assets/20a7e7e51e1f142b2b1f.js",
  "auth.password.forgot.css": "/assets/css/280c079c4407fbd0fdca.css",
  "auth.password.forgot.js": "/assets/280c079c4407fbd0fdca.js"
}

Retrieving paths

$webpackAssets = webpack();
// Full urls with hostname of filesystem. E.g. if disk driver is set to `public`, and `url` option
// is env('APP_URL').'/storage'
echo $webpackAssets->url('app.js'); // Output - http://host.dev/storage/assets/1b53147322421b069bf1.js
echo $webpackAssets->url('app.css'); // Output - http://host.dev/storage/assets/css/20a7e7e51e1f142b2b1f.css

// Absolute path for given filesystem. E.g. if disk driver is set to `public` and `root` parameter set to
// storage_path('app/public')
echo $webpackAssets->path('app.js'); // Output - /{project_dir}/storage/app/public/assets/1b53147322421b069bf1.js

// Relative paths, as they're presented inside json file
echo $webpackAssets->chunkPath('app.js'); // Output - /assets/1b53147322421b069bf1.js

Using in blade templates

Whenever you want to output your asset simply write:

{!! webpack_script('app.js') !!}

// or

{!! webpack()->image('background.png', 'Background') !!} 
// Output: <img alt="Background" src="http://host.dev/assets/e60cc0de08eee2256222218425eaa943.png">

Raw file contents

When you need to add inline file content, such as css or js wrapped with style or script tags you can now use helper functions for that: webpack_raw_style and webpack_raw_script, or if in object - webpack()->rawStyle() and webpack()->rawScript().

{!! webpack_raw_style('css/main.css') !!}

{{-- Or --}}

{!! webpack()->rawStyle('css/main.css') !!}

{{--Output--}}
<style>...content of main.css file...</style>

malyusha/laravel-webpack-assets 适用场景与选型建议

malyusha/laravel-webpack-assets 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.9k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2017 年 04 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「assets」 「laravel」 「mix」 「webpack」 「laravel assets」 「laravel-webpack」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 malyusha/laravel-webpack-assets 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-04-27