m-porter/vue-template-loader
Composer 安装命令:
composer require m-porter/vue-template-loader
包简介
Laravel package which will download your html templates as built by webpack-html-loader for use in your projects.
README 文档
README
Laravel package which will download your html templates as built by webpack-html-loader for use in your projects.
Intended for use with vue-cli.
Installation
Require this package with composer.
composer require m-porter/vue-template-loader
| Laravel version | This package version |
|---|---|
| ^6.0|^7.0 | ^6.0.0 |
| ^5.5,<5.9 | ^0.2.0 |
Package Discovery
If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php.
MPorter\VueTemplateLoader::class,
Configuration
Copy the package config to your local config with artisan's vendor:publish command:
php artisan vendor:publish --provider="MPorter\VueTemplateLoader\ServiceProvider"
Usage
This package is very opinionated and requires changes to your default vue.config.js file. Vue-template-loader is intended to be used with vue-cli's multi-page mode.
You can assume the following laravel project structure for this usage tutorial. (Modified directory structure after running vue create frontend).
<laravel project root>/frontend
├── package-lock.json
├── package.json
├── src
│ ├── example-app
│ │ ├── App.vue
│ │ ├── assets
│ │ │ └── logo.png
│ │ ├── components
│ │ │ └── HelloWorld.vue
│ │ ├── index.blade.php
│ │ └── main.js
└── vue.config.js
-
Remove the default
appentry withchainWebpack.// vue.config.js module.exports = { + chainWebpack: (config) => { + config.entryPoints.delete('app'); + }, }; -
Update
outputDirto point at laravel'spublicdirectory.// vue.config.js module.exports = { + outputDir: '../public/assets', chainWebpack: (config) => { config.entryPoints.delete('app'); }, }; -
Update
publicPathfor both local development and prod. This will allow you to use both hmr and built files locally.NODE_ENVwill already exist onprocess.envbutWEBPACK_HOSTandWEBPACK_PORTwill not. You will need to either add it to your npm scripts (e.g.WEBPACK_HOST=0.0.0.0 vue-cli-service serve) or use a npm package likedotenvto read your laravel.envfile.// vue.config.js + const isProd = process.env.NODE_ENV === 'production'; + const host = process.env.WEBPACK_HOST || '0.0.0.0'; + const port = process.env.WEBPACK_PORT || 8080; module.exports = { + publicPath: isProd ? '/assets' : `http://${host}:${port}/`, outputDir: '../public/assets', chainWebpack: (config) => { config.entryPoints.delete('app'); }, };
-
Update
pagesto include your frontend app. For this example, you can assume the following app structure.NOTE: Your folder CANNOT be named
app. This is a reserved folder name in vue-cli.// vue.config.js const isProd = process.env.NODE_ENV === 'production'; const host = process.env.WEBPACK_HOST || '0.0.0.0'; const port = process.env.WEBPACK_PORT || 8080; + const resourcePath = (n) => path.join('../../resources/views/vue', `${n}.blade.php`); + const filenameForEnv = (n) => (isProd ? resourcePath(n) : `${n}.html`); module.exports = { + pages: { + 'example-app': { + title: 'Example App', + entry: 'src/example-app/main.js', + template: 'src/example-app/index.blade.php', + filename: filenameForEnv('example-app'), + }, + }, publicPath: isProd ? '/assets' : `http://${host}:${port}/`, outputDir: '../public/assets', chainWebpack: (config) => { config.entryPoints.delete('app'); }, };
Two helper functions,
resourcePathandfilenameForEnv, were added to the config to help manage output file naming based on the current environment.resourcePathhandles sending the built html template to the vue-template-loader expectedresource_path('views/vue')directory it reads from on the PHP side. -
Test it out! Run
npm run servefrom your frontend directory and modify yourroutes/web.php.// routes/web.php use Illuminate\Support\Facades\Route; use MPorter\VueTemplateLoader\Loader; Route::get('/', function () { return view(Loader::getTemplate('example-app')); });
You should now be able to see the default vue page!
-
Update your
.gitignoreto avoid checking in built templates and files.public/assets/ resources/views/vue/
m-porter/vue-template-loader 适用场景与选型建议
m-porter/vue-template-loader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 03 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「html」 「loader」 「laravel」 「webpack」 「vue」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 m-porter/vue-template-loader 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 m-porter/vue-template-loader 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 m-porter/vue-template-loader 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Symfony2 bundle that provides features to load assets
An environment variable convenience library extension for vlucas/phpdotenv
PhpStratum SQLite: A stored procedure loader and wrapper generator for SQLite
Zend Framework 1 Loader package
HTML and form generation
统计信息
- 总下载量: 23
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-03-15