gin0115/vite-manifest-parser
Composer 安装命令:
composer require gin0115/vite-manifest-parser
包简介
A simple parser for Vue 3, VITE asset manifest files.
关键字:
README 文档
README
A basic parser for vite manifest file, which allows for the including of vue3-cli/vite projects in php.
Install
composer require gin0115/vite-manifest-parser
Usage
To accommodate the random hash which is added to assets compiled for vue 3 using vite , this library allows for the easy parsing of the required assets.
Example Vite Manifest
{
"main.js": {
"file": "assets/main.4889e940.js",
"src": "main.js",
"isEntry": true,
"dynamicImports": ["views/foo.js"],
"css": ["assets/main.b82dbe22.css"],
"assets": ["assets/asset.0ab0f9cd.png"]
},
"views/foo.js": {
"file": "assets/foo.869aea0d.js",
"src": "views/foo.js",
"isDynamicEntry": true,
"imports": ["_shared.83069a53.js"]
},
"_shared.83069a53.js": {
"file": "assets/shared.83069a53.js"
}
}
You can then access the assets using the following:
$manifest = new ViteManifestParser('https://www.url.tld/dist', 'path/to/project/vite.json');
// To access the main.js file url
// Just pass in the file name.
$mainJsUrl = $manifest->getEntryScriptUri('main.js');
// Returns https://www.url.tld/dist/assets/main.4889e940.js
// To access all CSS files.
$cssFiles = $manifest->getEntryCssUris('main.js');
// Returns [
// 'https://www.url.tld/dist/assets/main.b82dbe22.css'
// ];
API
ViteManifestParser()
The constructor takes 2 properties:
- assetUri - The base url of the assets.
- manifestPath - Path to the vite manifest file.
$parser = new ViteManifestParser('https://www.url.tld/dist', 'path/to/project/vite.json');
// This can also be used to set the base path, based on the environment.
$assetUrl = App::environment('local')
? 'http://localhost:8080/dist'
: 'https://www.url.tld/dist';
$parser = new ViteManifestParser($assetUrl, 'path/to/project/vite.json');
getAssetsUri
@return string The base url of the assets.
Returns the defined assetUri with any trailing slash removed.
$parser = new ViteManifestParser('https://www.url.tld/dist/', 'path/to/project/vite.json');
$parser->getAssetsUri(); // Returns 'https://www.url.tld/dist'
getAssetsForVueFile
@param string $fileName The name of the vue file.
@return array<string, string|string[]> The assets for the vue file.
@throws \Exception - File does not exist in manifest.
@throws \Exception - File assets are empty or invalid.
File Asset properties
- file: string
- src: string
- isEntry?: bool (optional)
- isDynamicEntry?: bool (optional)
- dynamicImports?: string[] (optional)
- css?: string[] (optional)
- assets?: string[] (optional)
- imports?: string[] (optional)
Returns an array of all details defined in the manifest for the given vue file.
$parser = new ViteManifestParser('https://www.url.tld/dist', 'path/to/project/vite.json');
$fileDetails = $parser->getAssetsForVueFile('main.js');
/*
* "file => "assets/main.4889e940.js",
* "src => "main.js",
* "isEntry => true,
* "dynamicImports => ["views/foo.js"],
* "css => ["assets/main.b82dbe22.css"],
* "assets => ["assets/asset.0ab0f9cd.png"]
*/
This will throw exceptions if there is an issue with the manifest file it self or the required file from manifest doesn't exist.
getEntryScriptUri
@param string $fileName - The filename of the asset
@return string|null - The url of the asset or null if file doesn't exist.
This will return just the main JS file uri, this will be prepended with the assetUri.
$parser = new ViteManifestParser('https://www.url.tld/dist', 'path/to/project/vite.json');
$mainJsUrl = $parser->getEntryScriptUri('main.js');
// Returns https://www.url.tld/dist/assets/main.4889e940.js
Unlike
getAssetsForVueFile(), this will not throw exceptions if the file doesn't exist and will just return null.
getEntryCssUris
@param string $fileName - The filename of the asset
@return string[] - The urls of the css assets.
This will return all css files that are defined for the entry file. This will be prepended with the assetUri.
$parser = new ViteManifestParser('https://www.url.tld/dist', 'path/to/project/vite.json');
$cssFiles = $parser->getEntryCssUris('main.js');
// Returns [
// 'https://www.url.tld/dist/assets/main.b82dbe22.css'
// ];
Unlike
getAssetsForVueFile(), this will not throw exceptions if the file doesn't exist and will just return an empty array.
Change log
- 0.1.0 - Initial release.
Contributing
If you would like to contribute to this project, please open an issue or pull request. All pull requests must pass the testing suite of PHPUnit, PHPStan and PHP Code Sniffer. To run these tests please run the following.
composer coverage- Runs the PHPUnit test cases and will create a HTML coverage report (if you have a valid coverage driver installed)composer test- Runs the PHPUnit test cases without the coverage report.composer sniff- Runs PHP Code Sniffer on the project.composer fixer- Runs PHPCBF against the files to the defined rules (PSR12).composer analyse- Runs the PHPStan ruleset for the projectcomposer all- Runs all of the above and is what is run as part of the GH Action pipeline.
All code must pass all of these suites against php versions 7.2 , 7.3 , 7.4 , 8.0 & 8.1 . On both windows and linux operating systems. Please note the Windows version runs less tests.
gin0115/vite-manifest-parser 适用场景与选型建议
gin0115/vite-manifest-parser 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 68 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 07 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「vue」 「vue-cli」 「vite」 「vue3」 「vue-manifest-parser」 「vue-asset-manifest-parser」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gin0115/vite-manifest-parser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gin0115/vite-manifest-parser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gin0115/vite-manifest-parser 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A component that allows creating responsive HTML tables or lists from data object
Injects assets from a Vite manifest to the Wordpress head, supports themes and plugins
Pimcore Vite integration
Admin panel generator for Laravel 8 and based on Vuetify Admin, a separate SPA admin framework running on top of REST APIs.
Code generation for MPMG projects that use Laravel and VueJs tecnologies.
Minimal Laravel authentication scaffolding with Vue, Vite, Typescript and Tailwind.
统计信息
- 总下载量: 68
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-25