vhanla / laravel-vue-cli
Laravel Vue Cli preset and integration
Installs: 66
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 1
Forks: 1
Open Issues: 0
Type:package
pkg:composer/vhanla/laravel-vue-cli
Requires
- illuminate/support: ^5.7
This package is auto-updated.
Last update: 2025-12-05 07:28:35 UTC
README
This package includes a preset that will modify a fresh Laravel 5.7 installation. It allows you to use Vue-cli along Laravel. It will also let you include them in your blade views, any assets generated by vue-cli-service.
Installation
With Composer
$ composer require vhanla/laravel-vue-cli
Next, add service provider into your config/app.php file in providers section:
Vhanla\VueCli\VuecliServiceProvider::class,
Configuration
To change package configuration you need to publish configuration files:
$ php artisan vendor:publish
This will publish vuecli.php file inside your config directory.
Usage
-
First create a
vueproject insideresourcesdirectory usingvue cli, it is recommended not to use git e.g.vue create --no-git <app-name> -
Once finished creation of
vueproject using Vue-Cli, execute thevueclipreset:php artisan preset vuecliand follow the interactive setup. The preset command will detectvueproject insideresourcesdirectory. Then it will ask you to pick it. -
Bladeviews has two methods to invoke assets.-
Development method: This method is better when we are developing.
<script src="{{ vuecli('app.js') }}"></script>It allows to always read generated
assets.jsonfile contents even from cached views. Recommended only for local development mode, specially when usinghashedfilenames. -
Cacheable method: This method is better for production mode.
<script src="@vuecli(app.js)"></script>Once
bladeview is cached, the returned assets path will always be the same, until thebladetemplate file is modified orphp artisan view:clearis invoked.
In other words, the first one will always read
public/assets.jsonfile in order to find out the specificassetfile, while the latter will only read once before caching. Even clearer, with the first one, cachedbladeviews will include<?php echo vuecli('app.js')...while the latter will not, instead it will write the path returned. -
Features
- Includes a
presetcommandvueclithat sets up a fresh Laravel project forvue cli. - You can use
vue ui. However, runningtasksfrom there seems to ignorevue.config.jsfile. It seems to be avue clibug. - Includes a
bladedirective@vuecli(assetname, boolean)where boolean value tells whether to ignore if asset is not found. - Includes a
helperfunctionvuecli('assetname', boolean)where boolean value tells whether to ignore not found asset. - Includes a
bladedirective@livereload(host,port)that adds it only if local (development) is detected.
Requirements
- Laravel 5.7 - maybe it would work on previous ones, I haven't tested.
vue cli3+webpack-manifest-pluginbutpresetwill add it, so just update it if newer version.webpack-livereload-pluginbutpresetwill add it too, so just update it if newer version.
Limitations
-
vue cliprojects has some limitations, specially a static and even mandatory static assets directorypublicwhose contents copies along with generated built assets into a defaultdistfolder, which as you can see, it will force us to somehow modify that folder tree structure in order to use it along Laravel's. But don't worry,vue.config.jsfile is configured to achieve that, by allowingpublicdirectory asoutputdirectory, and settings the static assetsresources/publicwhich also will contain theindex.phpfile thatyarn buildornpm run buildwill move to/publicdirectory. -
Vue development mode should be used only with
yarn serveornpm run serve, that's due to the previous issue, i.e. files and changes generated forvuein development mode won't be easily accessible from PHP's webserver side. -
HMR (Hot Module Replacement) is not included via Laravel's web server, only via
vue cli's. -
Some plugins for
vue clirequires to make sure anything that writes topublicdirectory be manually move toresources/publicdirectory.
Known issues
- If blank page is presented, make sure to use a virtual host a.k.a. local test domain, or update
baseUrlsincevueapp will find maybehttp://localhost/mylaravelapp/public/differentbaseUrlwhich by default expects to be/instead ofmylaravelapp/public. - If exception error about
my asset name.js, make sure it exists in/public/assets.json. - If error on
yarn buildornpm run buildshows- Propery "rules" is wrong type (expected object but got '[{}]')remove it frompackage.json.
TODO
- Improve handling of
vue clidevelopment, as of now,productionmode integrates better. - Improve handling of
vue cliplugins, since some still uses and overrides modifiedpublicassets directory. - Improve default spa.blade.php template