<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Fima Taf</title>
    <description>The latest articles on DEV Community by Fima Taf (@vbanditv).</description>
    <link>https://dev.to/vbanditv</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F511161%2Feea26242-eb73-463b-a045-e87263276704.png</url>
      <title>DEV Community: Fima Taf</title>
      <link>https://dev.to/vbanditv</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vbanditv"/>
    <language>en</language>
    <item>
      <title>NolybabJS - i18n-to-csv and csv-to-i18n converter</title>
      <dc:creator>Fima Taf</dc:creator>
      <pubDate>Sun, 19 Jun 2022 15:39:56 +0000</pubDate>
      <link>https://dev.to/vbanditv/nolybabjs-i18n-to-csv-and-csv-to-i18n-converter-43fk</link>
      <guid>https://dev.to/vbanditv/nolybabjs-i18n-to-csv-and-csv-to-i18n-converter-43fk</guid>
      <description>&lt;p&gt;After many frontend projects that I've worked with and tackled with the same problem - manually convert i18n json files into csv or manually creating keys for each language with the given translation, I've finally decided to create an open source library that will do it for me and save me (and maybe you) some time.&lt;/p&gt;

&lt;h3&gt;
  
  
  NolybabJS
&lt;/h3&gt;

&lt;p&gt;Nolybab is a CLI based i18n-to-csv and csv-to-i18n converter, you can easily convert your i18n json files into csv, and send it to your translators and when they finish to translate and send you the csv back - just convert it back to i18n files.&lt;/p&gt;

&lt;h4&gt;
  
  
  More info and examples can be found in the README file in the Github repository - &lt;a href="https://github.com/fima-taf/nolybab-js"&gt;nolybab-js&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;I would very much appreciate any kind of feedbacks or ideas that can improve this library.&lt;br&gt;
And of-course contribution is always welcome :)&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>webdev</category>
      <category>tooling</category>
      <category>javascript</category>
    </item>
    <item>
      <title>PNN Mirroring - determine yours workplace status</title>
      <dc:creator>Fima Taf</dc:creator>
      <pubDate>Fri, 29 Oct 2021 15:04:09 +0000</pubDate>
      <link>https://dev.to/vbanditv/pnn-mirroring-determine-yours-workplace-status-1dda</link>
      <guid>https://dev.to/vbanditv/pnn-mirroring-determine-yours-workplace-status-1dda</guid>
      <description>&lt;p&gt;&lt;strong&gt;PNN mirroring is about translating your thoughts and feelings into statuses and colors. PNN is an abbreviation of Positive, Neutral and Negative which mirrors the statuses and colors back to you. Continue reading and you'll figure it out&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Intro
&lt;/h3&gt;

&lt;p&gt;For many years there were studies and researches that tried to discover what is motivating employees to stay or to leave their work. Some of them were done by academic institutes, private companies, HR companies and others. Here are some of the common reasons that you can find in most of them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Relationship with management&lt;/li&gt;
&lt;li&gt;Organizational culture&lt;/li&gt;
&lt;li&gt;Compensation / Salary&lt;/li&gt;
&lt;li&gt;Commute time or distance&lt;/li&gt;
&lt;li&gt;Work-life balance&lt;/li&gt;
&lt;li&gt;Financial benefits&lt;/li&gt;
&lt;li&gt;Office benefits&lt;/li&gt;
&lt;li&gt;Co-workers&lt;/li&gt;
&lt;li&gt;Career growth&lt;/li&gt;
&lt;li&gt;Working remotely&lt;/li&gt;
&lt;li&gt;Professional and personal challenges&lt;/li&gt;
&lt;li&gt;Skill development&lt;/li&gt;
&lt;li&gt;Field related reason&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And there are many other reasons with which we can expand this list. &lt;/p&gt;

&lt;p&gt;There also might be field related reasons depending on the person's profession or the industry he is working in.&lt;br&gt;
Some people may see some of the above reasons as less important and some may see some of them as more important. It depends on the person's needs, character, culture, age and other factors.&lt;br&gt;
But if we will try to group those reasons we will get 4 main groups:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compensation and benefits&lt;/li&gt;
&lt;li&gt;People and community&lt;/li&gt;
&lt;li&gt;Self fulfillment&lt;/li&gt;
&lt;li&gt;Career&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Where it all started
&lt;/h3&gt;

&lt;p&gt;From the very beginning of your working career you are probably being asked a lot by your friends and family the question - "How's work?" - pretty annoying question and in most of the cases you will probably answer - "OK...". In some of the cases you'll detail the answer (maybe tell a little bit about the job itself or some other benefits you have there) &lt;strong&gt;but&lt;/strong&gt; you might also lie (maybe because of ego or to avoid unwanted conversation or any other reason) - and &lt;strong&gt;that is fine as long as you don't believe those lies.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once I talked to my friend and I heard in his voice that something was wrong. I asked him - "Is everything ok? Something related to your work?" and he replied - "I am not sure. The compensation is good, the people are friendly and nice, I am working with the tech stack I wanted but something feels wrong".&lt;br&gt;
I told him a bit about the tool I was thinking of and asked him if he wanted to be the 'pilot' user of it, and he agreed.&lt;br&gt;
Few days later he called me and said - "I've decided to quit the current job, and I understood that thanks to your tool". &lt;br&gt;
About a month later I was in the same situation but this time it was the other way around - my friend offered me to be the user of that tool. I agreed and this is the point where I actually realized the power of the tool that I came up with.&lt;br&gt;
After that I told to my wife - "I think I will start looking for a new job...", she was amazed. She asked me - "But just a few days ago everything was ok, what happened??", and I answered - "Nothing special happened, I just realized that I was lying to myself. But on the other hand the tool proved itself again". You can imagine my wife's facial expression...&lt;/p&gt;

&lt;h3&gt;
  
  
  The Problem
&lt;/h3&gt;

&lt;p&gt;The problem starts when you are &lt;strong&gt;lying to yourself&lt;/strong&gt;. Lying to yourself not necessarily has to be a 'pure lie', it can be an ignorance from a part of the situation like - "The arguments with my team leader are temporary, it's probably because he has a lot of pressure right now" while most of the team members doesn't get along with him as well, or "I will probably get a raise soon, I am doing a really good job" while no one got a raise or a bonus in the previous 3 years and the management doesn't care about their employees, or "I am working with a really good tech stack" while so little of the overall companies are looking for this tech stack and its popularity is going down every day. There are more examples, but I think you've got the point.&lt;br&gt;
Those thoughts and feelings cause you to ignore mostly the bad parts, maybe because you are a crazy level optimist (which is fine) or because you want to avoid facing the truth - Why? Because when you'll see the bigger picture you'll start considering making a change at your current workplace or even leaving your workplace and this is something that you maybe want to avoid at this point.&lt;br&gt;
Each and everyone has their own reasons for avoiding the bigger picture (relocation for this position, the efforts you've made to get there, personal financial issues, tired of all the interview processes and many other reasons).&lt;br&gt;
Some people may say - "Ye, that is fine, I can live with that.", but the question is - &lt;strong&gt;"What will be the consequences of this kind of living?"&lt;/strong&gt;. Those situations will lead mostly to &lt;strong&gt;anger and frustration&lt;/strong&gt;. It can be a slow process (which you can use to make some smart moves) but eventually it'll start getting out onto your relationship, family, kids, parents, friends, pets and of course - yourself. At some point you'll become desperate and probably will start looking for a new workplace, but at this point you'll try to find a workplace just to escape from your current one and not because that's a place that you were aiming for. &lt;br&gt;
The sooner you'll fix it the better. Trust me - I've been there...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If after reading the first part you think that you are ready to try it - then go for it and continue reading, otherwise come back when you'll feel that this is the right time.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  PNN Mirroring
&lt;/h2&gt;

&lt;p&gt;PNN mirroring is about translating your thoughts and feelings into statuses and colors. &lt;strong&gt;The whole idea is to keep it simple&lt;/strong&gt;. Remember the 4 groups we've aggregated at the intro? Now let's use them:&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1 (PNN)
&lt;/h3&gt;

&lt;p&gt;PNN - Positive, Neutral, Negative.&lt;br&gt;
Your task is to choose one of the following statuses for each group:&lt;br&gt;
&lt;strong&gt;Positive&lt;/strong&gt; 🟢&lt;br&gt;
&lt;strong&gt;Neutral&lt;/strong&gt;  ⚪️&lt;br&gt;
&lt;strong&gt;Negative&lt;/strong&gt; 🔴&lt;/p&gt;

&lt;h4&gt;
  
  
  Compensation and benefits [ ]
&lt;/h4&gt;

&lt;p&gt;This group includes: Salary, any kind of insurance, bonuses, office benefits, work-life balance, sick days, etc...&lt;/p&gt;

&lt;h4&gt;
  
  
  People and community [ ]
&lt;/h4&gt;

&lt;p&gt;This group includes: relationships with co-workers, relationships with management, interaction with other workers, social events, atmosphere at the workplace etc...&lt;/p&gt;

&lt;h4&gt;
  
  
  Self fulfillment [ ]
&lt;/h4&gt;

&lt;p&gt;This group is about your own goals. For example - Do you work at the position that you desire? Or at a position that will help you to get to the desired one? Are the missions/tasks you are dealing with are something that you wanted to do? Do you learn from the place you work in something that you wanted? Like - Leadership / mentoring / professional skills. Maybe you have a goal to change the world in some way (Save the environment / fight crime / help people / help animals / etc..) - Does this workplace help you to achieve this goal?&lt;/p&gt;

&lt;h4&gt;
  
  
  Career [ ]
&lt;/h4&gt;

&lt;p&gt;This group is a little bit different from the other three because it splits into two parts: common and field related.&lt;br&gt;
Common: Are you satisfied with the career path you chose? Does the current work push your career forward? &lt;br&gt;
Field related: This part may vary depending on your profession or field. As a fullstack developer I can say that the question that I've chosen is - Does the tech stack I am working with keeps me aligned to the market's demands?&lt;br&gt;
Let's say I am working mainly with technology A (I don't want to take a real one because some people may feel offended so I prefer to keep it generic and anonymous) and slowly this technology is dying - In 2/3/5 years I might find myself in a pretty bad position if I'll start looking for a new job.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you are not a programmer you'll have to think of a question that is related to your specific field.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 2 (Mirroring)
&lt;/h3&gt;

&lt;h4&gt;
  
  
  How to understand the results?
&lt;/h4&gt;

&lt;p&gt;Now write down / paint / imagine or any other way your result. (For example - 🟢🔴⚪️🟢)&lt;br&gt;
Look at the result and imagine that someone gave you this result and asks for an advice - &lt;strong&gt;What would you suggest he do?&lt;/strong&gt; &lt;br&gt;
Why? Because as humans it's much easier for us to tell someone else what to do than doing it ourselves.&lt;br&gt;
That is why it's called 'mirroring' it just reflects the image back to you. It might take you some time to process it and that is ok.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3 (Extra step)
&lt;/h3&gt;

&lt;p&gt;In case Step 2 is still confusing or you are having a hard time deciding what is the right status you're in, this extra step might be helpful.&lt;br&gt;
Order the groups by their importance to you when 1 is the most important and 4 is less important. (but keep in mind that even though you ordering the groups, they still have an equal amount - 25%) &lt;br&gt;
For example let's say that currently your friend's main focus is on his career path, the salary is much higher than his previous job but the co-workers he is working with are not the kind of people he would want to work with but his interaction with them is really low. Also this is not the 'dream job' he wants but he has to get experienced there to get to his dream job.&lt;br&gt;
If I'll use step 2 for the above situation I'll get this result - 🟢🔴⚪️🟢&lt;br&gt;
But if I'll order the result according to your friend's case (Career -&amp;gt; Compensation and benefits -&amp;gt; People and community -&amp;gt; Self fulfillment) I will get the following result:&lt;br&gt;
🟢&lt;br&gt;
🟢&lt;br&gt;
🔴&lt;br&gt;
⚪️&lt;/p&gt;

&lt;h3&gt;
  
  
  Q&amp;amp;A
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Why are there only 4 groups?&lt;/strong&gt;&lt;br&gt;
As I mentioned before - The whole idea is to keep it simple.&lt;br&gt;
Let's say my result was - 🟢⚪️🔴⚪️&lt;br&gt;
If I'll start breaking down the groups I might get the following result - 🟢⚪️🔴🟢🟢⚪️🔴🔴🟢⚪️&lt;br&gt;
Which one is clearer and simpler? &lt;br&gt;
For me personally the first one is much clearer, but if the second one is more clearer for you - then go for it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is there an app that I can use instead of writing/imagining?&lt;/strong&gt;&lt;br&gt;
While writing this post the idea of an app came to my mind, and I've already started working on it. I'll update this post whenever it'll be ready - so stay tuned :)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I move some of the amount of a group into another group?&lt;/strong&gt;&lt;br&gt;
"Let's say that currently my main goal is to earn a fortune and I don't really care about the people that I am working with - Can I take half of the amount from the 'People and community' group and move it to the 'Compensation and benefits' group?".&lt;br&gt;
The 4 groups that we've created at the intro have an equal effect on you (25%), even if you think that some of the groups are less important for you right now sooner or later it'll come out, that is why I wouldn't recommend doing it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Like everything else in the world PNN mirroring is not perfect and there might be scenarios in which it won't be able to help, but in the overall it might be very helpful (some of my friends that used it already were really happy that PNN mirroring helped them. Some of them said few bad words - but in the good way :D ).&lt;br&gt;
You are welcome to ask questions in case you have any, share (only if you want) any thoughts that came up and of-course if PNN mirroring helped you in any case I'll be very glad to hear (or read) about it. (You can write a PM if you want).&lt;br&gt;
Good luck and remember - &lt;strong&gt;'Experience' is mostly the mistakes you've made and learnt from and only a bit of the successful things you did&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>career</category>
      <category>motivation</category>
      <category>life</category>
    </item>
    <item>
      <title>Vite - A Short Overview</title>
      <dc:creator>Fima Taf</dc:creator>
      <pubDate>Wed, 07 Jul 2021 11:13:06 +0000</pubDate>
      <link>https://dev.to/vbanditv/vite-a-short-overview-4p17</link>
      <guid>https://dev.to/vbanditv/vite-a-short-overview-4p17</guid>
      <description>&lt;p&gt;There is a plan to run a hackathon at my company, and as the tech lead of the team I've been asked to choose the tech stack that we'll be using for our application. &lt;br&gt;
My immediate response was that I want us to try out using Vite for the frontend part after I was following it for a while and did some research about it. &lt;br&gt;
&lt;strong&gt;In this post I would like to share with you some of the features that Vite offers and to show a bit of how it works.&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Vite
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Vite (French word for "fast", pronounced /vit/) is a build tool that aims to provide a faster and leaner development experience for modern web projects. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Vite was created by Evan You (the same guy who created VueJS) and it seems that he used the same pattern with Vite as he used with VueJS - Simple, innovative, learning from others mistakes and taking care of many configurations by default &lt;strong&gt;BUT&lt;/strong&gt; in case you need to go deeper and modify any of them - you can do it pretty easy.&lt;br&gt;
Some of those configurations that Vite is providing out-of-the-box are - JSX, TypeScript, Web Workers, CSS and more. &lt;/p&gt;

&lt;p&gt;Unlike other bundling tools Vite is using only &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules" rel="noopener noreferrer"&gt;ES Modules&lt;/a&gt; both at development and production - Lets see how:&lt;/p&gt;
&lt;h2&gt;
  
  
  Development
&lt;/h2&gt;

&lt;p&gt;Vite is running &lt;a href="https://koajs.com" rel="noopener noreferrer"&gt;Koa&lt;/a&gt; - a light weight dev server which is serving native ES modules and using &lt;a href="https://esbuild.github.io" rel="noopener noreferrer"&gt;esbuild&lt;/a&gt; for dependency pre-bundling.  &lt;/p&gt;
&lt;h5&gt;
  
  
  What is dependency pre-bundling?
&lt;/h5&gt;

&lt;p&gt;According to Vite's docs dependency pre-bundling has 2 reasons:&lt;br&gt;
&lt;strong&gt;1) CommonJS and UMD compatibility -&lt;/strong&gt; While Vite is using only native ES modules some of the libraries you are using or might use won't be using ES modules, instead it'll use CommonJS or UMD. To solve this issue Vite is converting all the dependencies from CommonJS and UMD into ES modules using &lt;code&gt;esbuild&lt;/code&gt;. &lt;br&gt;
Vite is performing this action when you run the dev server for the first time (That is why the first run might be longer then the other runs). &lt;br&gt;
&lt;strong&gt;What if I add a new dependency or upgrade a version of an exiting one?&lt;/strong&gt; Not a problem - Vite will watch the changes in &lt;code&gt;package.json&lt;/code&gt; / &lt;code&gt;package-lock.json&lt;/code&gt; / &lt;code&gt;yarn.lock&lt;/code&gt; / &lt;code&gt;pnpm-lock.yaml&lt;/code&gt; and will rebuild the dependency. In case there are some issues you can delete the cache folder &lt;code&gt;node_modules/.vite&lt;/code&gt; or rerun the server with the &lt;code&gt;--force&lt;/code&gt; flag and Vite will rebuild all the dependencies.&lt;br&gt;
&lt;strong&gt;2) Performance -&lt;/strong&gt; Each dependency can have a large number of it's own modules which will cause the browser to fire a crazy amount of requests to the backend so Vite is converting those dependencies into a single ES module to reduce the amount of the requests being fired.&lt;/p&gt;
&lt;h3&gt;
  
  
  Running the dev server
&lt;/h3&gt;

&lt;p&gt;Lets run the server:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fts545piwsc4828grgpao.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fts545piwsc4828grgpao.jpg" alt="vite-run"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now Lets compare it to vue-cli (webpack):&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fye8ikxsx6d4ysdi0yeta.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fye8ikxsx6d4ysdi0yeta.jpg" alt="vue-cli-run"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see Vite is faster on both runs. But the question is - &lt;strong&gt;How?&lt;/strong&gt; (We'll get an answer for this question later)&lt;/p&gt;
&lt;h3&gt;
  
  
  Native ES Modules
&lt;/h3&gt;

&lt;p&gt;As I've mentioned earlier Vite is using only ES modules. If we take a look at &lt;code&gt;index.html&lt;/code&gt; file, we'll see this line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;module&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/src/main.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;type="module"&lt;/code&gt; attribute is an ES6 feature that is using native ES modules. All the modern browsers are already supporting this feature. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F62dqyhrkxmudezindle6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F62dqyhrkxmudezindle6.png" alt="2021-07-06 00_09_09-Window"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The image above is showing the 'Waterfall' effect that ES modules create - starting from &lt;code&gt;main.js&lt;/code&gt; and importing all the modules down the modules tree. And as you can see each vue component and dependency is being split in a separate module.&lt;br&gt;&lt;br&gt;
Unlike vue-cli (webpack) that by default has only 2 scripts:&lt;br&gt;
&lt;code&gt;app.js&lt;/code&gt; containing all the components of the application. &lt;br&gt;
&lt;code&gt;chunk-vendors.js&lt;/code&gt; is basically all the &lt;code&gt;node_modules&lt;/code&gt; dependencies.&lt;br&gt;
&lt;em&gt;webpack does has a way to split the components and dependencies into chunks, but it requires you to configure this option OR manually selecting files/modules you want to chunk.&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Another interesting thing here is that each vue component file has also a css file that is being loaded - &lt;strong&gt;Why?&lt;/strong&gt; HMR.&lt;/p&gt;

&lt;h3&gt;
  
  
  HMR
&lt;/h3&gt;

&lt;p&gt;Vite's Hot Module Replacement is one of the main reasons that Vite is so fast. It using web-socket just like webpack and other bundling tools, but the difference is that with the combination of ESM it works very fast even if your application will grow by replacing only 1 module and not re-bundling a big file.&lt;br&gt;
Lets take vue-cli (webpack) for an example:&lt;br&gt;
By default it has only 2 files (as mentioned above), on each HMR call the whole &lt;code&gt;app.js&lt;/code&gt; will be re-bundled and sent to the browser.&lt;br&gt;
&lt;strong&gt;Where is the problem?&lt;/strong&gt; &lt;br&gt;
When the amount of the components will start growing so do &lt;code&gt;app.js&lt;/code&gt;'s size and the time it takes.&lt;br&gt;
With Vite on the other hand it'll be much faster because there is no need to re-bundle such a big file - it will only replace the actual component / file that was changed without 'touching' the other components / files. That is why there is also a css file that we've mentioned earlier - If you going to make a change only to the  &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; of a component - then only the &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; of that component will be replaced by HMR and not the whole component. &lt;br&gt;
So it means that if your app will have 1 or 1000 or 10000 components the time that the HMR process will take will remain almost the same (of-course it also depending on the size of the file, just avoid creating monster size components...).&lt;/p&gt;

&lt;h2&gt;
  
  
  Production
&lt;/h2&gt;

&lt;p&gt;For production Vite is still bundling the code according to the official docs: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Even though native ESM is now widely supported, shipping unbundled ESM in production is still inefficient (even with HTTP/2) due to the additional network round trips caused by nested imports.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The cool 'waterfall' effect you saw above is really fast and useful  when you're working with a dev server on your localhost, but this advantage can become a disadvantage when it comes to loading performance. &lt;br&gt;
For production bundling Vite is using &lt;a href="https://rollupjs.org/guide/en/" rel="noopener noreferrer"&gt;rollup.js&lt;/a&gt; which is also using ESM when building the app for production and it does that faster and with a smaller file size then webpack for example.&lt;/p&gt;

&lt;h2&gt;
  
  
  Downsides
&lt;/h2&gt;

&lt;p&gt;Vite is not perfect and it also has its downsides:&lt;br&gt;&lt;br&gt;
&lt;strong&gt;1. Old browsers support -&lt;/strong&gt; Old browsers (IE) doesn't support ESM, therefor applications created by Vite is not gonna work there.&lt;br&gt;
&lt;strong&gt;2. Different dev and production builds -&lt;/strong&gt; As you saw Vite is using different tools for development and production which has the possibility to cause problems and bugs that will appear only in one of the environments but not at the other.&lt;br&gt;
&lt;strong&gt;3. Ecosystem -&lt;/strong&gt; Vite is still new in the neighborhood and the ecosystem is still small. There are issues/bugs/problems that will probably appear in the near and far future that'll have to be handled, while webpack for example has a pretty big ecosystem that solves a wide variety of edge cases.&lt;/p&gt;

&lt;h3&gt;
  
  
  So should I stop using vue-cli or webpack and switch to Vite?
&lt;/h3&gt;

&lt;p&gt;Well, it's up to you. My advice - First try it out, test it, build a small demo app -&amp;gt; then if you want to start working on a real project consider the advantages and disadvantages that I've listed above - and then make your decision. &lt;/p&gt;

&lt;h3&gt;
  
  
  Libraries and frameworks support
&lt;/h3&gt;

&lt;p&gt;In this post I've showed all the examples with VueJS, but Vite supports also other libraries and frameworks:&lt;br&gt;&lt;br&gt;
&lt;strong&gt;VueJs, React, Preact, Svelte, LitElement.&lt;/strong&gt; (And probably more will join)&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Vite seems to be a really good and promising build tool with nice features, newer tech usage and an alternative to other build tools.&lt;br&gt;&lt;br&gt;
Its not perfect (like every thing in our world...) so I think you should give it a try, and even if it won't fit your needs I suggest you to follow it and watch how it gonna evolve and maybe then consider trying it again.&lt;/p&gt;

&lt;p&gt;Hope this post made the understanding of Vite a bit easier.&lt;br&gt;
Thank you for reading :)&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>vue</category>
      <category>vite</category>
      <category>webpack</category>
    </item>
    <item>
      <title>How to add FCM (Firebase Cloud Messaging) to VueJS </title>
      <dc:creator>Fima Taf</dc:creator>
      <pubDate>Mon, 08 Mar 2021 17:09:15 +0000</pubDate>
      <link>https://dev.to/vbanditv/how-to-add-fcm-firebase-cloud-messaging-to-vuejs-37np</link>
      <guid>https://dev.to/vbanditv/how-to-add-fcm-firebase-cloud-messaging-to-vuejs-37np</guid>
      <description>&lt;p&gt;Lately I had a task to implement FCM (Firebase Cloud Messaging) to a vue application I am working on, and I've found out that there are few guides but they didn't helped me too much because FCM's API, vue cli and vue it self were updated since then, so I've decided to write down a small and updated guide for it. &lt;/p&gt;

&lt;h1&gt;
  
  
  Step 1 - Add the service worker file
&lt;/h1&gt;

&lt;p&gt;The first thing that we need to do is to add the service worker file &lt;code&gt;firebase-messaging-sw.js&lt;/code&gt; to the &lt;code&gt;public&lt;/code&gt; folder (It's important to use this file name because firebase will look for this file with that specific name, it can be changed tough but not in this guide - sorry).&lt;br&gt;
(If you are not familiar with the words 'service worker' you can learn more about it &lt;a href="https://developers.google.com/web/fundamentals/primers/service-workers"&gt;Here&lt;/a&gt; or &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker"&gt;Here&lt;/a&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//firebase-messaging-sw.js&lt;/span&gt;

&lt;span class="nx"&gt;importScripts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://www.gstatic.com/firebasejs/8.2.7/firebase-app.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;importScripts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://www.gstatic.com/firebasejs/8.2.7/firebase-messaging.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;firebaseConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;API&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;KEY&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;authDomain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;AUTH&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;DOMAIN&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;projectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;PROJECT&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;storageBucket&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;STORAGE&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;BUCKET&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;messagingSenderId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MESSAGING&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;SENDER&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;appId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;APP&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;measurementId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MEASUREMENT&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;initializeApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firebaseConfig&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Replace the config json above with the one you got from firebase&lt;/strong&gt;&lt;br&gt;
Go to your project home page at firebase -&amp;gt; Press on the Settings icon -&amp;gt; click 'Project Settings' -&amp;gt; Scroll down -&amp;gt; &lt;code&gt;firebaseConfig&lt;/code&gt; object&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Step 2 - Register the service worker
&lt;/h1&gt;

&lt;p&gt;The next step is to register the service worker.&lt;br&gt;
We have few ways of doing that:&lt;/p&gt;
&lt;h4&gt;
  
  
  * If you prefer using firebase package jump to Step 3.
&lt;/h4&gt;
&lt;h3&gt;
  
  
  * Using vue cli's PWA plugin
&lt;/h3&gt;

&lt;p&gt;If you've created your application through vue cli (v3+) and you've added the PWA support option (or added this plugin manually after the installation) you can register the service worker with &lt;code&gt;registerServiceWorker.js&lt;/code&gt; file as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//registerServiceWorker.js&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;register&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;register-service-worker&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;firebase-messaging-sw.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;You can learn more about the above plugin and its events &lt;a href="//github.com/yyx990803/register-service-worker"&gt;Here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  * Using vanilla JS
&lt;/h3&gt;

&lt;p&gt;If you prefer to register the service worker using only JS, you can add the following code (anywhere in your application):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;serviceWorker&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;serviceWorker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;firebase-messaging-sw.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reg&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Service Worker Registration (Scope: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;reg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;)`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`Service Worker Error (&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;)`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// happens when the app isn't served over HTTPS or if the browser doesn't support service workers&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;warn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Service Worker not available&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Step 3 - Using firebase module
&lt;/h1&gt;

&lt;p&gt;Another way to register the service worker and subscribe to FCM is by installing the firebase package.&lt;br&gt;
&lt;code&gt;npm install firebase&lt;/code&gt;&lt;br&gt;
After you've installed the package, create a file called &lt;code&gt;firebase.js&lt;/code&gt; (or any other name you want) and add the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//firebase.js&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;firebase&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;firebase/app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;firebase/firebase-messaging&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;firebaseConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;API&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;KEY&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;authDomain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;AUTH&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;DOMAIN&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;projectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;PROJECT&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;storageBucket&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;STORAGE&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;BUCKET&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;messagingSenderId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MESSAGING&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;SENDER&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;appId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;APP&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;measurementId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MEASUREMENT&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;initializeApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firebaseConfig&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;messaging&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Why do I need to instanciate firebase again? I already did it on step 1...
&lt;/h4&gt;

&lt;p&gt;Because the service worker is running on another thread and not on the main one, therefor we cannot pass the instance to our main application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add FCM in vue 2
&lt;/h3&gt;

&lt;p&gt;To add FCM as a global in your vue 2 application go to your &lt;code&gt;main.js&lt;/code&gt; file and add the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//main.js&lt;/span&gt;

&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;firebaseMessaging&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./firebase&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$messaging&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firebaseMessaging&lt;/span&gt;

&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can access FCM instance everywhere in your application by calling &lt;code&gt;this.$messaging&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add FCM in vue 3
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Add as a global
&lt;/h4&gt;

&lt;p&gt;You can add FCM as a global in vue 3 but then it &lt;strong&gt;won't&lt;/strong&gt; be accessible in composition's API &lt;code&gt;setup()&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//main.js&lt;/span&gt;

&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;firebaseMessaging&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./firebase&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;globalProperties&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$messaging&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firebaseMessaging&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can call it in every component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//RandomComponent.vue&lt;/span&gt;

&lt;span class="p"&gt;...&lt;/span&gt;
  &lt;span class="nx"&gt;mounted&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Firebase cloud messaging object&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$messaging&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Use Provide/Inject
&lt;/h4&gt;

&lt;p&gt;Another way that vue 3 is providing to pass data is the Provide/Inject feature. (You can learn more about it &lt;a href="https://v3.vuejs.org/guide/component-provide-inject.html#working-with-reactivity"&gt;Here&lt;/a&gt;)&lt;br&gt;
In your &lt;code&gt;App.vue&lt;/code&gt; (or any other component you want the 'Super Parent' to be) add the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//App.vue&lt;/span&gt;

&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;provide&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;firebaseMessaging&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./firebase&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//options api&lt;/span&gt;
  &lt;span class="na"&gt;provide&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;messaging&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;firebaseMessaging&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="c1"&gt;//composition api&lt;/span&gt;
  &lt;span class="nx"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;provide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;messaging&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;firebaseMessaging&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And Now you can call it by injecting it into any child component you want, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//RandomChildComponent.vue&lt;/span&gt;

&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;inject&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//options api&lt;/span&gt;
  &lt;span class="na"&gt;inject&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;messaging&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="nx"&gt;mounted&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Firebase cloud messaging object&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$messaging&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="c1"&gt;//composition api&lt;/span&gt;
  &lt;span class="nx"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;messaging&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;inject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;messaging&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Firebase cloud messaging object&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;messaging&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Step 4 - Subscribe
&lt;/h1&gt;

&lt;p&gt;After the service worker has been registered we can subscribe our client to FCM by calling the &lt;code&gt;getToken()&lt;/code&gt; function.&lt;br&gt;
Go back to &lt;code&gt;firebase-messaging-sw.js&lt;/code&gt; (if you used step 2) or call firebase's &lt;code&gt;messaging&lt;/code&gt; object (if you used step 3) and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="c1"&gt;//firebase-messaging-sw.js (step 2)&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;messaging&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;getToken&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;vapidKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;KEY&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;//RandomChildComponent.vue (step 3)&lt;/span&gt;
&lt;span class="nx"&gt;messaging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getToken&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;vapidKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;KEY&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To get the vapidKey go to firebase console:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Go to your project home page at firebase -&amp;gt; Press on the Settings icon -&amp;gt; click 'Project Settings' -&amp;gt; 'Cloud Messaging' tab -&amp;gt; 'Web configuration' &amp;gt; 'Web Push certificates'&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;In case you want to get the specific token of each client you can add the following to your &lt;code&gt;getToken()&lt;/code&gt; function:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;messaging&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;getToken&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;vapidKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;KEY&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;currentToken&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentToken&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;client token&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentToken&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;No registration token available. Request permission to generate one.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;An error occurred while retrieving token. &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  In case you used step 3 (firebase package) &lt;code&gt;getToken()&lt;/code&gt; method will also register the service worker for you.
&lt;/h5&gt;

&lt;h4&gt;
  
  
  The &lt;code&gt;getToken()&lt;/code&gt; function will subscribe to FCM and since this moment your client will get push notification from FCM. yey :)
&lt;/h4&gt;

&lt;p&gt;Hope it helped you somehow, enjoy :)&lt;/p&gt;

</description>
      <category>vue</category>
      <category>webdev</category>
      <category>firebase</category>
    </item>
    <item>
      <title>Including Vuejs application in another web application (with vue-cli &gt;3 and Vite)</title>
      <dc:creator>Fima Taf</dc:creator>
      <pubDate>Fri, 05 Feb 2021 17:15:29 +0000</pubDate>
      <link>https://dev.to/vbanditv/including-vuejs-application-in-another-web-application-with-vue-cli-3-h27</link>
      <guid>https://dev.to/vbanditv/including-vuejs-application-in-another-web-application-with-vue-cli-3-h27</guid>
      <description>&lt;h2&gt;
  
  
  Update:
&lt;/h2&gt;

&lt;p&gt;Scroll to the bottom of the page if you want to achieve the same with Vite.&lt;/p&gt;

&lt;p&gt;Recently I've got a task at my current company to write a small vue application (1 page only) and inject it into an existing legacy project (JSP in that case - I know it's old and ugly, but sometimes it's part of the job...). &lt;br&gt;
I've been told that there is already a vue application that is being injected into the legacy application and it is working pretty nice, so I thought to my self 'Lets see how they configured it there, and use the same way to implement the new app'. &lt;br&gt;
And then I realized that's not gonna work because the existing vue application was created 2 years ago and it was probably created with &lt;code&gt;vue-cli&lt;/code&gt; 1 or 2 with all the 'pure' webpack configurations, while I am using &lt;code&gt;vue-cli&lt;/code&gt; 3 in the new application (which has the &lt;code&gt;vue.config.js&lt;/code&gt; file instead all the previous webpack config, and the other app has too much custom webpack configuration that it became too messy).&lt;/p&gt;

&lt;p&gt;After I've searched the web for a solution for this problem, I didn't found something that solved my problem. Finally I've managed to solve it and I wanted to share it so maybe it'll help to someone else.&lt;/p&gt;
&lt;h3&gt;
  
  
  Overview
&lt;/h3&gt;

&lt;p&gt;Vue is by default using the SPA (&lt;a href="https://www.bloomreach.com/en/blog/2018/07/what-is-a-single-page-application.html"&gt;What is SPA?&lt;/a&gt;) approach which in this case is an advantage.&lt;br&gt;
&lt;strong&gt;This example is probably not gonna work with SSR approach&lt;/strong&gt; (&lt;a href="https://ssr.vuejs.org"&gt;What is SSR?&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;After running &lt;code&gt;npm run build&lt;/code&gt; command, you'll have all the generated files inside the &lt;code&gt;dist&lt;/code&gt; folder.&lt;br&gt;
In our case the generated &lt;code&gt;index.html&lt;/code&gt; &lt;strong&gt;won't be used&lt;/strong&gt; because we are going to include our vue application in another html file.&lt;br&gt;
The files that we &lt;strong&gt;will use&lt;/strong&gt; are &lt;code&gt;app.[hash].js&lt;/code&gt; and &lt;code&gt;chunk-vendors.[hash].js&lt;/code&gt;.&lt;br&gt;
These 2 files are enough for vue to work, the app file is gonna import all the others files (js/css/etc..) that the application needs in order to work properly.&lt;/p&gt;
&lt;h3&gt;
  
  
  Including vue inside another app
&lt;/h3&gt;
&lt;h5&gt;
  
  
  1) Move the generated files:
&lt;/h5&gt;

&lt;p&gt;As I mentioned before vue is by default using the SPA approach, so basically what we need to do is to take the content of the generated &lt;code&gt;dist&lt;/code&gt; folder and put it somewhere in the existing app. (Don't forget to remove the &lt;code&gt;index.html&lt;/code&gt;)&lt;br&gt;
It is important to keep the content order as it (don't move the js files from the js folder or the css files because the &lt;code&gt;app&lt;/code&gt; file will import the other files relative to his location).&lt;/p&gt;
&lt;h5&gt;
  
  
  2) Let the existing app to import vue app files:
&lt;/h5&gt;

&lt;p&gt;Choose the html file in which you want the vue app to be included, and add the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"js/app.[hash].js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"js/chunk-vendors.[hash].js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure that the scripts will be loaded &lt;strong&gt;after&lt;/strong&gt; vue's root div (&lt;code&gt;&amp;lt;div id="app"&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt;) - If the scripts will be loaded &lt;strong&gt;before&lt;/strong&gt; the root div, the vue application won't work.&lt;/p&gt;

&lt;p&gt;Basically this is it, if you run your existing application, your vue app will work inside the html page that you've chosen to include it in.&lt;/p&gt;

&lt;h3&gt;
  
  
  Extras
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Running on local environment
&lt;/h4&gt;

&lt;p&gt;Of course before building the vue app you'll want to develop and test your vue app on your local environment.&lt;br&gt;
In order to do that, you just need to replace the path of the js files at the html file to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"http://localhost:8080/js/app.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"http://localhost:8080/js/chunk-vendors.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that when running the vue app at dev mode it doesn't use the hash at the file name, the hash is being used only when building the app for production.&lt;/p&gt;

&lt;h4&gt;
  
  
  Import the files from external source
&lt;/h4&gt;

&lt;p&gt;In some cases you'll want to keep the build files of the vue app in a different location and configure your existing app to loaded it from an external source (your-domain.com, AWS S3, Azure Blob, etc...).&lt;br&gt;
There is a great webpack plugin that will help you with that - &lt;br&gt;
&lt;a href="https://github.com/agoldis/webpack-require-from"&gt;webpack-require-from&lt;/a&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Example:
&lt;/h5&gt;

&lt;p&gt;If you have some server that is running on the domain &lt;code&gt;your-cool-domain.com&lt;/code&gt; and this server will hold the vue app files, you can add a global variable at your existing app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;vueAppSrc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://your-cool-domain.com/files/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now in your vue app install the plugin &lt;code&gt;npm install webpack-require-from -D&lt;/code&gt;.&lt;br&gt;
Then in the &lt;code&gt;vue.config.js&lt;/code&gt; file add the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;WebpackRequireFrom&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;webpack-require-from&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;chainWebpack&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;plugin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;require-from&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;WebpackRequireFrom&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt; &lt;span class="na"&gt;variableName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vueAppSrc&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}])&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now all the files of your vue app will be loaded from the url you've set in the global variable. (&lt;code&gt;https://your-cool-domain.com/files/app.[hash].js&lt;/code&gt;)&lt;/p&gt;

&lt;h4&gt;
  
  
  Why there are 2 'base' files and not only 1?
&lt;/h4&gt;

&lt;p&gt;Until webpack v4 we didn't had the &lt;code&gt;chunk-vendors.[hash].js&lt;/code&gt; file, and all the third party modules were inside the app file, but since webpack v4 (vue-cli 3 is using webpack v4) webpack is splitting the app and the third party modules into different files by default for a better performance.&lt;/p&gt;

&lt;h4&gt;
  
  
  Can I reduce it to 1 file only?
&lt;/h4&gt;

&lt;p&gt;Yes, it is possible by adding the following option into your &lt;code&gt;vue.config.js&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;configureWebpack&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;optimization&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;splitChunks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration will move the whole content of &lt;code&gt;chunk-vendors&lt;/code&gt; file inside the &lt;code&gt;app&lt;/code&gt; file (just like before webpack v4).&lt;br&gt;
&lt;strong&gt;This option will have effect on the performance, so take it in count.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Vite
&lt;/h3&gt;

&lt;p&gt;I've wanted to achieve the same thing with Vite, but because Vite's production build is based on &lt;code&gt;rollup&lt;/code&gt; (which works different from webpack - you can learn more about it &lt;a href="https://dev.to/vbanditv/vite-a-short-overview-4p17"&gt;Here&lt;/a&gt;) I've created a plugin for the same issue:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;vite-plugin-loading-script&lt;/code&gt; is a vite plugin for wrapping and loading the generated files/assets with a single script into the DOM instead of &lt;code&gt;index.html&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can learn about the plugin in the Docs &lt;a href="https://github.com/fima-taf/vite-plugin-loading-script"&gt;Here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The generated file will appear in the app's &lt;code&gt;dist&lt;/code&gt; folder - &lt;code&gt;app.[hash].js&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclution
&lt;/h3&gt;

&lt;p&gt;It is pretty easy to include (or inject) a vue application into another web application.&lt;br&gt;
But keep in mind that there might be some other problems that I didn't tackled in my case so it's not perfect, but still might be useful to someone else.&lt;/p&gt;

&lt;p&gt;Hope it'll help you (at least partially) :)&lt;/p&gt;

</description>
      <category>vue</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
