Create a distributable widget with VueJS in Laravel backend

Mauro Sassaroli
Mar 15 · 2 min read

Recently I came across the problem of having to deliver a widget, for a client to place it on their site.

The backend is developed in Laravel, and the few things that it had of the front end, were made with VueJs.

I was wondering how to make a deliverable/distributable widget with VueJs and found this post

That is perfect, except that in the example, everything was done from vue-cli.

To integrate it into Laravel, what I did was create a new js file, which only includes the components of the widget, and add it to the webpack.mix.js

In this sliders.js (the widget is a product slider) I made the inclusion of Vue, the main component and the creation of the custom element

Then, everything can be worked normally like any other component.

Once the development is finished, run npm run prod and this generates the sliders.js and the sliders.css and to deliver the widget to any client, just send the url of these two files and the name of the custom element:

<link rel="stylesheet" href="">
<script src=""></script><custom-slider slider-id="4" site-id="site1"></custom-slider>

And that would be all.

I hope this helps, thank you.

Mauro Sassaroli

Written by

Full stack Developer. Laravel & VueJs. Viajar, comer y compartir