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.
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,
To change package configuration you need to publish configuration files:
$ php artisan vendor:publish
This will publish vuecli.php
file inside your config
directory.
-
First create a
vue
project insideresources
directory usingvue cli
, it is recommended not to use git e.g.vue create --no-git <app-name>
-
Once finished creation of
vue
project using Vue-Cli, execute thevuecli
preset:php artisan preset vuecli
and follow the interactive setup. The preset command will detectvue
project insideresources
directory. Then it will ask you to pick it. -
Blade
views 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.json
file contents even from cached views. Recommended only for local development mode, specially when usinghashed
filenames. -
Cacheable method: This method is better for production mode.
<script src="@vuecli(app.js)"></script>
Once
blade
view is cached, the returned assets path will always be the same, until theblade
template file is modified orphp artisan view:clear
is invoked.
In other words, the first one will always read
public/assets.json
file in order to find out the specificasset
file, while the latter will only read once before caching. Even clearer, with the first one, cachedblade
views will include<?php echo vuecli('app.js')...
while the latter will not, instead it will write the path returned. -
- Includes a
preset
commandvuecli
that sets up a fresh Laravel project forvue cli
. - You can use
vue ui
. However, runningtasks
from there seems to ignorevue.config.js
file. It seems to be avue cli
bug. - Includes a
blade
directive@vuecli(assetname, boolean)
where boolean value tells whether to ignore if asset is not found. - Includes a
helper
functionvuecli('assetname', boolean)
where boolean value tells whether to ignore not found asset. - Includes a
blade
directive@livereload(host,port)
that adds it only if local (development) is detected.
- Laravel 5.7 - maybe it would work on previous ones, I haven't tested.
vue cli
3+webpack-manifest-plugin
butpreset
will add it, so just update it if newer version.webpack-livereload-plugin
butpreset
will add it too, so just update it if newer version.
-
vue cli
projects has some limitations, specially a static and even mandatory static assets directorypublic
whose contents copies along with generated built assets into a defaultdist
folder, 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.js
file is configured to achieve that, by allowingpublic
directory asoutput
directory, and settings the static assetsresources/public
which also will contain theindex.php
file thatyarn build
ornpm run build
will move to/public
directory. -
Vue development mode should be used only with
yarn serve
ornpm run serve
, that's due to the previous issue, i.e. files and changes generated forvue
in 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 cli
requires to make sure anything that writes topublic
directory be manually move toresources/public
directory.
- If blank page is presented, make sure to use a virtual host a.k.a. local test domain, or update
baseUrl
sincevue
app will find maybehttp://localhost/mylaravelapp/public/
differentbaseUrl
which 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 build
ornpm run build
shows- Propery "rules" is wrong type (expected object but got '[{}]')
remove it frompackage.json
.
- Improve handling of
vue cli
development, as of now,production
mode integrates better. - Improve handling of
vue cli
plugins, since some still uses and overrides modifiedpublic
assets directory. - Improve default spa.blade.php template