I have been working on a chat plugin for HTML using VueJs, the problem is that I don’t know how to create a plugin that can be used to deploy this plugin on any website.
Basically I want to make a GET request which gets the chat plugin into any website. EG: Facebook Messenger Chat Plugin
I have the build files for this chat view. What should be my next move?
Thanks in advance!
Advertisement
Answer
I solved this problem by building the VueJs file and removing the , , , from the built file and then importing it into any HTML file using:-
JavaScript
x
9
1
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
2
<div id="floating-chat"></div>
3
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
4
<script type="text/javascript">
5
axios.get('https://dfe43d80.ngrok.io/views').then(({data})=>{
6
$('#floating-chat').html(data);
7
}).catch(err=>console.log(err));
8
</script>
9
Don’t forget to replace all the links from the server and use express.static
JavaScript
1
13
13
1
app.use(express.static(__dirname+'/dist'));
2
3
fs.readFile(__dirname + '/dist/index.html', 'utf8', (err, html)=>{
4
if(err){
5
console.log(err);
6
}
7
html.replace('href=/js',`href=https://YOURWEBISTE.COM/js`);
8
html.replace('href=/css',`href=https://YOURWEBISTE.COM/css`);
9
html.replace('src=/js',`src=https://YOURWEBISTE.COM/js`);
10
console.log(html);
11
res.send(html);
12
});
13
And use CORS to let other pages import your HTML content.