<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[360learntocode - Medium]]></title>
        <description><![CDATA[About Java, Grails and Groovy, Python, A.I, Machine Learning, and other programming languages. - Medium]]></description>
        <link>https://medium.com/360learntocode?source=rss----f0254769325f---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>360learntocode - Medium</title>
            <link>https://medium.com/360learntocode?source=rss----f0254769325f---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 19:53:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/360learntocode" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[VueJs PWA: Notify User about the App Update | skipWaiting]]></title>
            <link>https://medium.com/360learntocode/vuejs-pwa-notify-user-about-the-app-update-skipwaiting-4496cd51b17f?source=rss----f0254769325f---4</link>
            <guid isPermaLink="false">https://medium.com/p/4496cd51b17f</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[service-worker]]></category>
            <category><![CDATA[vue-3]]></category>
            <category><![CDATA[pwa-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[kumar chapagain]]></dc:creator>
            <pubDate>Mon, 14 Apr 2025 11:54:31 GMT</pubDate>
            <atom:updated>2025-04-14T11:54:31.326Z</atom:updated>
            <content:encoded><![CDATA[<p>Once the application is updated and deployed, the new version will be available. But how can we notify the user that a newer version is available while they are interacting with the application? How to give the user control over app updates.</p><h3>1. Understanding how the UI get an update when new content is available:</h3><p>When you change the app content and deploy it, you can see in the browser what the service worker is trying to do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/0*dk3gXMy5fgXBWUTA.png" /></figure><p>Here, you can see, as soon as the new content is available new service worker trying to install it and is in waiting state.</p><p>However, the old service worker is registered and serving with the old content. The new service worker will still be in a skip waiting state i.e, waiting.</p><p>Here, once we notify the user about the new update and if they allow us to update the app, we can simply do skip waiting and reload the page for new content. After that, a new service worker will be activated and will serve with a new update available.</p><h3>2. Register the custom event to notify the user about the app update:</h3><p>We know that service worker can’t access the web DOM element directly. As they will run in the background in a separate thread. So we have to notify users from our application. In order to do so, we need to register the custom event, which can be listened to in the application.</p><p>You can see the file <strong><em>registerServiceWorker.js </em></strong>which is generated by Vue CLI.</p><pre>import { register } from &#39;register-service-worker&#39;<br> <br>if (process.env.NODE_ENV === &#39;production&#39;) {<br>  register(`${process.env.BASE_URL}service-worker.js`, {<br>    ready () {<br>      console.log(<br>        &#39;App is being served from cache by a service worker.\n&#39; +<br>        &#39;For more details, visit https://goo.gl/AFskqB&#39;<br>      )<br>    },<br>    registered () {<br>      console.log(&#39;Service worker has been registered.&#39;)<br>    },<br>    cached () {<br>      console.log(&#39;Content has been cached for offline use.&#39;)<br>    },<br>    updatefound () {<br>      console.log(&#39;New content is downloading.&#39;)<br>    },<br>    updated () {<br>      console.log(&#39;New content is available; please refresh.&#39;)<br>    },<br>    offline () {<br>      console.log(&#39;No internet connection found. App is running in offline mode.&#39;)<br>    },<br>    error (error) {<br>      console.error(&#39;Error during service worker registration:&#39;, error)<br>    }<br>  })<br>}</pre><p>There are multiple events that will be triggered. Here, we need to use the updated hook to notify the user. Let’s register for the custom event.</p><pre>updated (registration) {<br>      console.log(&#39;New content is available; please refresh.&#39;)<br>      document.dispatchEvent(<br>          new CustomEvent(&#39;serviceWorkerUpdateEvent&#39;, { detail: registration })<br>      );<br>    },</pre><p>Now let’s add this event listener <strong><em>serviceWorkerUpdateEvent </em></strong>in our application. Inside <strong><em>App.vue</em></strong></p><pre>created() {<br>    document.addEventListener(<br>        &#39;serviceWorkerUpdateEvent&#39;, this.appUpdateUI, { once: true }<br>    );<br>  },</pre><p>Let’s add some data used and appUpdateUI function.</p><pre>data: () =&gt; ({<br>    registration:null,<br>    isRefresh: false,<br>    refreshing: false,<br>  }),<br>  methods:{<br>    appUpdateUI:function (e){<br>      this.registration = e.detail;<br>      this.isRefresh = true;<br>    }<br>  }</pre><p>When the <strong><em>updated </em></strong>event inside <strong><em>registerServiceWorker.js</em></strong> is triggered then <strong><em>serviceWorkerUpdateEvent</em></strong> will be triggered, which calls the appUpdateUI to show the button to update. Let’s add a simple button inside the template as a user interface to update the app. You can use a nicer snack bar instead.</p><pre>&lt;button v-if=&quot;isRefresh&quot; @click=&quot;update&quot;&gt;Update&lt;/button&gt;</pre><p>Let’s add <strong><em>update()</em></strong> inside the methods.</p><pre> update(){<br>     this.isRefresh = false;<br>     if (this.registration || this.registration.waiting) {<br>       this.registration.waiting.postMessage({type:&#39;SKIP_WAITING&#39;});<br>     }<br>   },</pre><p>Now when the user clicks the update button then it will send the post message of type ‘SKIP_WAITING’ to communicate with the service worker.</p><p>If you are using <strong><em>GenerateSW </em></strong>mode, then make sure this post message matches the <strong><em>message listener</em></strong> inside the service worker. You can verify it by building your app. Once the app is built, then under <strong><em>dist/</em></strong> folder, you can find the service-worker.js to verify.</p><p>If you are using <strong><em>injectManifest </em></strong>mode, then use the message listener as below inside <strong><em>service-worker.js:</em></strong></p><pre> self.addEventListener(&#39;message&#39;, (event) =&gt; {<br>  if (event.data &amp;&amp; event.data.type === &#39;SKIP_WAITING&#39;) {<br>    self.skipWaiting();<br>  }<br>});</pre><p>Now, this listener will be triggered, and it will do skip waiting. The last thing is we need to reload the application to reflect the content change.</p><p>For this, we can use ‘<strong><em>controllerchange</em></strong>’ listener in our application. Under <strong><em>App.vue</em></strong> inside <strong><em>created </em></strong>use the following listener.</p><pre> created() {<br>    navigator.serviceWorker.addEventListener(<br>        &#39;controllerchange&#39;, () =&gt; {<br>          if (this.refreshing) return;<br>          this.refreshing = true;<br>          window.location.reload();<br>        }<br>    );<br>  },</pre><p>This is the idea to notify the user of the App update.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4496cd51b17f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/360learntocode/vuejs-pwa-notify-user-about-the-app-update-skipwaiting-4496cd51b17f">VueJs PWA: Notify User about the App Update | skipWaiting</a> was originally published in <a href="https://medium.com/360learntocode">360learntocode</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[VueJs: How to Get the App Version from package.json]]></title>
            <link>https://medium.com/360learntocode/vuejs-how-to-get-the-app-version-from-package-json-fcaeaa92bd70?source=rss----f0254769325f---4</link>
            <guid isPermaLink="false">https://medium.com/p/fcaeaa92bd70</guid>
            <category><![CDATA[vue-3]]></category>
            <category><![CDATA[app-version]]></category>
            <category><![CDATA[packagejson]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[kumar chapagain]]></dc:creator>
            <pubDate>Mon, 07 Apr 2025 10:00:43 GMT</pubDate>
            <atom:updated>2025-04-07T10:00:43.189Z</atom:updated>
            <content:encoded><![CDATA[<h3>This is a quick tutorial on how we can access the app version.</h3><p>While building applications, there may be different phases of development. We need to have a clear vision that which version of the application is on the server.</p><p>In the VueJs application, under <strong><em>package.json</em></strong> file, you can see the one property called <strong><em>version</em></strong>. We can use this version while deploying to indicate the different versions of the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/0*fSTpAVcBC6puziGj.png" /></figure><p>So, what we can do is simply increase the value for a different version of development.</p><p>The version can be accessed in our application by simply importing this file as below:</p><pre>import {version} from &#39;../../package&#39;</pre><p>Make sure it’s accessible. Here, e.g ‘../../’ will give the access for the package which is used under /src/somefolder/component.vue. As the package.json file is under the app root directory. If you want it inside App.vue you can use ‘../’ instead.</p><pre>data: () =&gt; ({<br>    appVersion:version<br>  }),</pre><p>Now access your template or set in the store and access it.</p><pre>&lt;h1&gt;{{appVersion}}&lt;/h1&gt;</pre><p>If you want the package version inside npm script:</p><pre>const version = process.env.npm_package_version</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fcaeaa92bd70" width="1" height="1" alt=""><hr><p><a href="https://medium.com/360learntocode/vuejs-how-to-get-the-app-version-from-package-json-fcaeaa92bd70">VueJs: How to Get the App Version from package.json</a> was originally published in <a href="https://medium.com/360learntocode">360learntocode</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Use and Customize Service Worker in VueJs Progressive Web Apps(PWA)]]></title>
            <link>https://medium.com/360learntocode/how-to-use-and-customize-service-worker-in-vuejs-progressive-web-apps-pwa-dab8a28d60d3?source=rss----f0254769325f---4</link>
            <guid isPermaLink="false">https://medium.com/p/dab8a28d60d3</guid>
            <category><![CDATA[service-worker]]></category>
            <category><![CDATA[customize-serviceworker]]></category>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[vue-3]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[kumar chapagain]]></dc:creator>
            <pubDate>Mon, 07 Apr 2025 09:44:48 GMT</pubDate>
            <atom:updated>2025-04-07T09:44:48.873Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. Introduction:</h3><p>What exactly a service worker? What is the need for a service worker in our web application?</p><p>The service worker is the script that runs in the browser in the background. This means the service worker will run in a separate thread and is independent of our web pages. Service worker can’t access the DOM directly.</p><p>The service worker is very handy for the caching strategy, push notification, and background sync. This means we can manage which files need to be cache and which do not.</p><p>Also particularly for mobile app, when it is not opened and needs to send the push notification as well as if the app is not opened and needs to send the request to the server.</p><h3>2. Default Implementation of Service Worker in VueJs PWA:</h3><p>VueJs application with Vue CLI uses the default configuration to set up and use the service worker.</p><p>If you build your application then, you can see the service worker file generated.</p><pre>yarn build</pre><p>There are two webpack plugin mode, one is <strong><em>GenerateSW </em></strong>mode which will generate the complete service worker. Vue CLI uses this as a default mode.</p><p>Another is InjectManifest mode, which allows us to customize and organize as our requirement and we do have full control over service worker.</p><p>If you want to know when to use and when not to use these modes please visit <a href="https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin">Workbox webpack Plugins</a></p><p>You can see the default service worker generated after building the application as shown in the figure above.</p><p>We are going to use the <strong><em>InjectManifest </em></strong>mode so that we can have control over the service worker.</p><h3>3. Register the Service Worker:</h3><p>The service worker registration is done by Vue CLI by default. You can see the <strong><em>registerServiceWorker.js</em> </strong>under <strong><em>/src</em></strong> folder, the file looks as below:</p><pre>/* eslint-disable no-console */<br> <br>import { register } from &#39;register-service-worker&#39;<br> <br>if (process.env.NODE_ENV === &#39;production&#39;) {<br>  register(`${process.env.BASE_URL}service-worker.js`, {<br>    ready () {<br>      console.log(<br>        &#39;App is being served from cache by a service worker.\n&#39; +<br>        &#39;For more details, visit https://goo.gl/AFskqB&#39;<br>      )<br>    },<br>    registered () {<br>      console.log(&#39;Service worker has been registered.&#39;)<br>    },<br>    cached () {<br>      console.log(&#39;Content has been cached for offline use.&#39;)<br>    },<br>    updatefound () {<br>      console.log(&#39;New content is downloading.&#39;)<br>    },<br>    updated () {<br>      console.log(&#39;New content is available; please refresh.&#39;)<br>    },<br>    offline () {<br>      console.log(&#39;No internet connection found. App is running in offline mode.&#39;)<br>    },<br>    error (error) {<br>      console.error(&#39;Error during service worker registration:&#39;, error)<br>    }<br>  })<br>}</pre><p>Note: make sure to change the service worker name if you use a different name for it.</p><p>Here, the service worker is enabled only for production, enabling service worker in development mode is not encouraged, as it will not reflect the current changes in development, instead it will use cached resources. All the events will be triggered in different cases.</p><h3>4. Customize Service Worker with InjectManifest Mode:</h3><p>Let’s copy the service worker service-worker.js file from the dist/ folder or create a new service-worker.js file under the src/ directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/0*Ca9FNnK17lJC6l-G.png" /></figure><p>Now, let’s configure the config to notice that we are using the <strong><em>InjectManifiest </em></strong>mode and provide the newly created service worker path to use that service worker.</p><p>For this, create a <strong><em>vue.config.js</em></strong> file under the app root directory. Make sure to have the same name mentioned so this config file will be used by Vue CLI. The file looks as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MA0cHRBOl9j62tWa.png" /></figure><p>Now, lets set up the config:</p><pre> pwa:{<br>        workboxPluginMode: &quot;InjectManifest&quot;,<br>        workboxOptions:{<br>            swSrc:&quot;./src/service-worker.js&quot;,<br>        }<br>    }</pre><p>Add the above PWA configuration inside the <strong><em>vue.config.js</em></strong> file. Here, we are using plugin mode as InjectManifest and give the path of the newly created service-worker.js file.</p><p>The custom service worker file needs to be as shown below:</p><pre> workbox.core.setCacheNameDetails({prefix: &quot;vue-pwa&quot;});<br> <br>self.__precacheManifest = [].concat(self.__precacheManifest || []);<br>workbox.precaching.precacheAndRoute(self.__precacheManifest, {});<br> <br>self.addEventListener(&#39;message&#39;, (event) =&gt; {<br>    if (event.data &amp;&amp; event.data.type === &#39;SKIP_WAITING&#39;) {<br>        self.skipWaiting();<br>    }<br>});</pre><p>Let’s change the cache name from <strong><em>“vue-pwa”</em></strong> to <strong><em>“vue-pwa-test” </em></strong>and build the application. If you look into the <strong><em>service-worker.js</em></strong> under the <strong><em>dist/</em></strong> folder and if you see the changes there, you are good to go.</p><p>Also, you can see some import scripts added at the beginning of the file by Vue CLI which looks something like below.</p><pre>importScripts(&quot;/precache-manifest.7b241a43a2278739512d45eb32884cc1.js&quot;, &quot;https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js&quot;);</pre><p>The precache-manifest has a different JSON config for different files to cache. Note that the file name to be cached will be different in each build. Now, build and deploy the application.</p><p><strong><em>Note: Each change in the application will be reflected in the browser after new content is updated and the app is reloaded or refreshed</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/0*Gn0r7qTbuVdpS06o.png" /></figure><p>Now, click on “skipWaiting” and reload the page, which will reload our application with new changes. We will do this <strong><em>skipWaiting</em></strong> from the application in the next tutorial by giving the user control of the app update. Or if you do it right away, especially for testing, you can add the following inside <strong><em>service-worker.js.</em></strong></p><pre>workbox.core.skipWaiting();</pre><p>You can see the caching files under the cache storage tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/0*kS7qc7tqAiipyH7E.png" /></figure><p>The life cycle of the service worker is implemented by default. You can handle each event/hooks inside <strong><em>registerServiceWorker.js</em></strong> file as mentioned in step 3.</p><p>Now, you can especially handle different push notifications, background sync, using indexdb inside this custom service worker created.</p><h3>5. Service Worker Life Cycle Event:</h3><p>If you want to implement the lifecycle event on your own you can use them inside the <strong><em>service-worker.js</em></strong> file itself. Make sure to unregister the service worker from the <strong><em>registerServiceWorker.js</em></strong> file and register your service worker. It can be done in the <strong><em>main.js</em></strong> file. Some of the life cycle events are below:</p><pre>self.addEventListener(&#39;install&#39;, (event) =&gt; {<br>  console.log(&quot;Installing ....................&quot;);<br>});<br>self.addEventListener(&#39;activate&#39;, (event) =&gt; {<br>  console.log(&quot;activateing ....................&quot;);<br>});<br>self.addEventListener(&#39;fetch&#39;, (event) =&gt; {<br>  console.log(&quot;fetching ....................&quot;);<br>});<br>self.addEventListener(&#39;message&#39;, (event) =&gt; {<br>  if (event.data &amp;&amp; event.data.type === &#39;SKIP_WAITING&#39;) {<br>    self.skipWaiting();<br>  }<br>});</pre><p>If you want to know more about these events, please look at <a href="https://developers.google.com/web/fundamentals/primers/service-workers">Service Workers: an Introduction.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dab8a28d60d3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/360learntocode/how-to-use-and-customize-service-worker-in-vuejs-progressive-web-apps-pwa-dab8a28d60d3">How to Use and Customize Service Worker in VueJs Progressive Web Apps(PWA)</a> was originally published in <a href="https://medium.com/360learntocode">360learntocode</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[VueJs Progressive Web Apps(PWA): How to Change the App Name, Icon, Color, Display for Mobile…]]></title>
            <link>https://medium.com/360learntocode/vuejs-progressive-web-apps-pwa-how-to-change-the-app-name-icon-color-display-for-mobile-0a87df1b97df?source=rss----f0254769325f---4</link>
            <guid isPermaLink="false">https://medium.com/p/0a87df1b97df</guid>
            <category><![CDATA[pwa-development]]></category>
            <category><![CDATA[vue-3]]></category>
            <category><![CDATA[manifest]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[pwa]]></category>
            <dc:creator><![CDATA[kumar chapagain]]></dc:creator>
            <pubDate>Sun, 06 Apr 2025 17:07:23 GMT</pubDate>
            <atom:updated>2025-04-06T17:07:23.514Z</atom:updated>
            <content:encoded><![CDATA[<h3><a href="https://www.360learntocode.com/2020/12/how-to-change-app-name-icon-color-display-of-vuejs-pwa.html">VueJs Progressive Web Apps(PWA): How to Change the App Name, Icon, Color, Display for Mobile Devices.</a></h3><p>In this tutorial, I will show you how to create and change the Manifest file. The manifest file will allow the way of displaying our application, especially on mobile devices, i.e showing the app name, app icon for different size mobile screens, the color of the app, etc.</p><p><strong>Create a Manifest file.</strong></p><p>The default manifest file will be created when you build your application with Vue CLI. Let’s build our application.</p><pre>yarn build</pre><p>Now you can see the <strong><em>manifest.json</em></strong> file under the <strong><em>dist/</em></strong> folder. This is the file that we are going to modified according to our requirements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/0*2w93T9uUZ-hdHJAQ.png" /></figure><p>To change this file, first copy the file inside the public/ folder. On each build, all the files under the public folder will be copied to the dist/ folder so we have our changes in production.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/0*HxEla27wo2JXaqGF.png" /></figure><p>The<strong><em> manifest.json</em></strong> file looks like below:</p><pre>{<br>  &quot;name&quot;: &quot;vue-pwa&quot;,<br>  &quot;short_name&quot;: &quot;vue-pwa&quot;,<br>  &quot;theme_color&quot;: &quot;#4DBA87&quot;,<br>  &quot;icons&quot;: [<br>    {<br>      &quot;src&quot;: &quot;./img/icons/android-chrome-192x192.png&quot;,<br>      &quot;sizes&quot;: &quot;192x192&quot;,<br>      &quot;type&quot;: &quot;image/png&quot;<br>    },<br>    {<br>      &quot;src&quot;: &quot;./img/icons/android-chrome-512x512.png&quot;,<br>      &quot;sizes&quot;: &quot;512x512&quot;,<br>      &quot;type&quot;: &quot;image/png&quot;<br>    },<br>    {<br>      &quot;src&quot;: &quot;./img/icons/android-chrome-maskable-192x192.png&quot;,<br>      &quot;sizes&quot;: &quot;192x192&quot;,<br>      &quot;type&quot;: &quot;image/png&quot;,<br>      &quot;purpose&quot;: &quot;maskable&quot;<br>    },<br>    {<br>      &quot;src&quot;: &quot;./img/icons/android-chrome-maskable-512x512.png&quot;,<br>      &quot;sizes&quot;: &quot;512x512&quot;,<br>      &quot;type&quot;: &quot;image/png&quot;,<br>      &quot;purpose&quot;: &quot;maskable&quot;<br>    }<br>  ],<br>  &quot;start_url&quot;: &quot;.&quot;,<br>  &quot;display&quot;: &quot;standalone&quot;,<br>  &quot;background_color&quot;: &quot;#000000&quot;<br>}</pre><p>We will discuss each property used here. If you have difficulties generating this file make sure to create one with this structure.</p><p>If you deploy with this default configuration and open it on your mobile then you can see the below display.</p><p><strong>Note: We are using the default Vue CLI application for testing.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/283/0*JXGvRzg7h2XGAUk7.png" /></figure><p><strong>name :</strong></p><p>This will be the name displayed on the screen(splash screen) before the application loads the CSS. Please change the name you want for your application. When you click the icon then you will see this name and icon as a first screen.</p><p><strong>short_name:</strong></p><p>This is similar to the <strong><em>name </em></strong>property but displayed under the launcher icon as shown above.</p><p><strong>theme_color</strong>:</p><p>The default theme color of the application.</p><p><strong>icons:</strong></p><p>Different icons are used for different screen mobile devices. For example the different launcher icon size for the different screens for the Android device looks as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/0*rzsNNAqdTZlkEeIs.png" /></figure><p>Make sure to put different size image icons for your app under <strong>public/img/icons</strong> folders, or if you want to use them in a different folder inside public/, then use the same path on the manifest.json file.</p><p>By providing different size icons, the icon will be used according to the different screen sizes of devices.</p><p><strong>start_url:</strong></p><p>This will be the URL for the entry point when you add the app to the home screen.</p><p><strong>display:</strong></p><p>“that determines the developers’ preferred display mode for the website. The display mode changes how much of the browser UI is shown to the user and can range from the browser (when the full browser window is shown) to fullscreen (when the app is full-screened).”</p><p><strong>background_color:</strong></p><p>This defines the background color of the splash screen before the application CSS is loaded. When you click the app on your device, initially, it will load the background color with icons before the app is loaded.</p><p>For other properties and more descriptions, please visit <a href="https://developer.mozilla.org/en-US/docs/Web/Manifest">Web App Manifest.</a></p><p>Finally, make changes to the properties under <strong><em>manifest.json</em></strong> and build the application, and then deploy. You can see the desired changes in your mobile devices.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0a87df1b97df" width="1" height="1" alt=""><hr><p><a href="https://medium.com/360learntocode/vuejs-progressive-web-apps-pwa-how-to-change-the-app-name-icon-color-display-for-mobile-0a87df1b97df">VueJs Progressive Web Apps(PWA): How to Change the App Name, Icon, Color, Display for Mobile…</a> was originally published in <a href="https://medium.com/360learntocode">360learntocode</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Deploy VueJs Application to Firebase for Different Environment]]></title>
            <link>https://medium.com/360learntocode/how-to-deploy-vuejs-application-to-firebase-for-different-environment-349897a7d14c?source=rss----f0254769325f---4</link>
            <guid isPermaLink="false">https://medium.com/p/349897a7d14c</guid>
            <category><![CDATA[env]]></category>
            <category><![CDATA[deploy]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[vue-3]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[kumar chapagain]]></dc:creator>
            <pubDate>Fri, 28 Mar 2025 14:10:39 GMT</pubDate>
            <atom:updated>2025-03-28T14:10:39.338Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial, we are going to deploy our Vue application to the Firebase server for different environments.</p><p>Before putting any project into production, it needs to be developed QA first.</p><p>So, for different cases, we may need different configurations and need to use different server resources.</p><p>According to this requirement, we need to set up different configuration files for different environments. So, while deploying, it can take a specific config for the corresponding environment.</p><p>Generally, what we are going to do is:</p><ol><li>Create different projects for different environments in firebase</li><li>Set up firebase hosting in our application</li><li>Configuring test config file for different environment</li><li>Deploy the application for different environments</li></ol><p><strong>1. Create projects in firebase for different environments</strong></p><p>Go to the “https://console.firebase.google.com/&quot; and create a project.</p><p>Here we are creating two sample projects for <strong>develop</strong> and <strong>qa</strong> environment.</p><ul><li>Give the name of the project, we are giving “develop-vue-test” to develop and “qa-vue-test” to qa environment</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/0*pDWKs5d_b1VJZqs1.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/0*rehJ_Pg2zAjzk-pN.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/0*emb9E7GL9Kd0gZLw.png" /></figure><p><strong>Note: Create two different projects for two different environments.</strong></p><p><strong>2. Set up a firebase hosting in our application.</strong></p><p>Here, we are considering you already have your vuejs application. Go to the project directory and initialize the firebase.</p><p><strong>- Install Firebase CLI:</strong></p><p>For npm package manager:</p><pre>npm install -g firebase-tools</pre><p>For yarn package manager:</p><pre>yarn global add firebase-tools</pre><ul><li><strong>Initialize your project:</strong></li></ul><pre>firebase login</pre><p>This will redirect you to log in with a Google account. Use the same account to log in which is used to create for the different firebase projects previously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/0*Xb6O9foke_rFDxWL.png" /></figure><p>Now, initialize the firebase project using the following command:</p><pre>firebase init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*io24dwHbva2zeBd_.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5wj-T2emQ76Zdsgy.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/0*a4lz-wWlJRiM1Z89.png" /></figure><p>The above process will create the following two different files in your project directory:</p><ul><li><strong>.firebaserc:</strong></li></ul><pre> <br>{<br>  &quot;projects&quot;: {<br>    &quot;default&quot;: &quot;develop-vue-test&quot;<br>  }<br>}</pre><p>As we use the default firebase project as “develop-vue-test” while doing <strong><em>firebase init</em></strong>.</p><ul><li><strong>firebase.json</strong></li></ul><pre>{<br>  &quot;hosting&quot;: {<br>    &quot;public&quot;: &quot;dist&quot;,<br>    &quot;ignore&quot;: [<br>      &quot;firebase.json&quot;,<br>      &quot;**/.*&quot;,<br>      &quot;**/node_modules/**&quot;<br>    ],<br>    &quot;rewrites&quot;: [<br>      {<br>        &quot;source&quot;: &quot;**&quot;,<br>        &quot;destination&quot;: &quot;/index.html&quot;<br>      }<br>    ]<br>  }<br>}</pre><p>This is the firebase config file, where you can see the setup we did previously. For e.g “public”: “dist” as we choose dist as public.</p><p><strong>3. Configuring test config file for the different environment:</strong></p><p>Now, let’s create some config files in the project directory for different env.</p><p>For production:</p><p>.env.production</p><p>For develop:</p><p>.env.develop</p><pre>VUE_APP_ENDPOINT=https://develop.com</pre><p>You can create whatever config key-value pair here with the respective environment. We are using VUE_APP_ENDPOINT test sample.</p><p>For qa:</p><p>.env.qa</p><pre>VUE_APP_ENDPOINT=https://qa.com</pre><p>You can access that config file property anywhere by using:</p><pre>process.env.VUE_APP_ENDPOINT</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/0*sTKfq6b-Yc9cRkse.png" /></figure><p>Now, let’s add a <strong><em>qa-vue-test</em></strong> firebase project inside firebase.json</p><pre>{<br>  &quot;projects&quot;: {<br>    &quot;default&quot;: &quot;develop-vue-test&quot;,<br>    &quot;qa&quot;: &quot;qa-vue-test&quot;<br>  }<br>}</pre><p>Let’s go to the package.json file and add and change the build script to use this config file.</p><pre>&quot;scripts&quot;: {<br>    &quot;serve&quot;: &quot;vue-cli-service serve&quot;,<br>    &quot;build&quot;: &quot;vue-cli-service build&quot;,<br>    &quot;develop&quot;: &quot;vue-cli-service build --mode develop&quot;,<br>    &quot;qa&quot;: &quot;vue-cli-service build --mode qa&quot;<br>  },</pre><p>Here, we added two more scripts for develop and qa environment.</p><p><em>“develop”: “vue-cli-service build — mode develop”,</em></p><p><em>“qa”: “vue-cli-service build — mode qa”</em></p><p><strong>4. Deploy the application:</strong></p><p><strong>For develop:</strong></p><pre>yarn develop</pre><p>Which will build the application for develop env.</p><pre>firebase deploy</pre><p>Inside the firebase.json file, the default project is selected as <strong><em>develop-vue-test,</em></strong> so it will simply deploy to develop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/0*yJYZl2pVul3iNq37.png" /></figure><p><strong>For qa:</strong></p><pre>yarn qa</pre><pre>firebase deploy -P qa</pre><p>Make sure the name “qa” needs to same as the name of the project defined in firebase.json. This will simply deploy the build folder to “qa-vue-test” firebase project.</p><p>Finally, we have successfully deployed our Vue.js application to Firebase for different environments.</p><p>If you want to track the hosting inside the firebase console, then you can go to the <strong>Hosting </strong>tab in the console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gwetc8cWJVz7HUIJ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=349897a7d14c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/360learntocode/how-to-deploy-vuejs-application-to-firebase-for-different-environment-349897a7d14c">How to Deploy VueJs Application to Firebase for Different Environment</a> was originally published in <a href="https://medium.com/360learntocode">360learntocode</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Implement Webcam in VueJs Application]]></title>
            <link>https://medium.com/360learntocode/how-to-implement-webcam-in-vuejs-application-229c63b6dfa6?source=rss----f0254769325f---4</link>
            <guid isPermaLink="false">https://medium.com/p/229c63b6dfa6</guid>
            <category><![CDATA[vue-3]]></category>
            <category><![CDATA[pictures]]></category>
            <category><![CDATA[webcam]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[kumar chapagain]]></dc:creator>
            <pubDate>Wed, 26 Mar 2025 15:48:18 GMT</pubDate>
            <atom:updated>2025-03-26T15:48:18.844Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial, we are going to implement a webcam in the Vuejs application.</p><p>Generally, what it does is:</p><ol><li>Stream the video from the webcam</li><li>Capture photos from the streaming video</li><li>Preview the captured photo</li><li>Convert it into the file to send to the server</li></ol><p>The overall implementation looks as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MQcwH3QvRCY8kWWJ.gif" /></figure><p><strong>1. Create a sample Vuejs application.</strong></p><p>Open the terminal or command prompt and create the application.</p><pre>vue create vue-camera</pre><p>Select the default option or select manually, where you can choose to set it up.</p><pre>cd vue-camera<br>yarn serve</pre><p><strong>2. Create a Vuejs webcam component</strong></p><p>Now, let’s create a component called Camera.vue.</p><pre>&lt;div class=&quot;camera-box&quot;&gt;<br>    &lt;div style=&quot;display: flex; justify-content: center;&quot;&gt;<br>        &lt;img style=&quot;height: 25px;&quot; v-if=&quot;isCameraOpen&quot;<br>             src=&quot;https://img.icons8.com/material-outlined/50/000000/camera--v2.png&quot;<br>             class=&quot;button-img camera-shoot&quot; @click=&quot;capture&quot;/&gt;<br>        &lt;div class=&quot;camera-button&quot;&gt;<br>            &lt;button type=&quot;button&quot; class=&quot;button is-rounded cam-button&quot;<br>                    style=&quot;margin-left: 40%; background-color: white; border: 0px;&quot;<br>                    @click=&quot;toggleCamera&quot;<br>            &gt;<br>        &lt;span v-if=&quot;!isCameraOpen&quot;&gt;&lt;img style=&quot;height: 25px;&quot; class=&quot;button-img&quot;<br>                                        src=&quot;https://img.icons8.com/material-outlined/50/000000/camera--v2.png&quot;&gt;&lt;/span&gt;<br>                &lt;span v-else&gt;&lt;img style=&quot;height: 25px;&quot; class=&quot;button-img&quot;<br>                                  src=&quot;https://img.icons8.com/material-outlined/50/000000/cancel.png&quot;&gt;&lt;/span&gt;<br>            &lt;/button&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>    &lt;div style=&quot;height: 200px&quot;&gt;<br>        &lt;div v-if=&quot;isCameraOpen&quot; class=&quot;camera-canvas&quot;&gt;<br>            &lt;video ref=&quot;camera&quot; :width=&quot;canvasWidth&quot; :height=&quot;canvasHeight&quot; autoplay&gt;&lt;/video&gt;<br>            &lt;canvas v-show=&quot;false&quot; id=&quot;photoTaken&quot; ref=&quot;canvas&quot; :width=&quot;canvasWidth&quot; :height=&quot;canvasHeight&quot;&gt;&lt;/canvas&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>&lt;/div&gt;</pre><p>Let’s set the data used.</p><pre>export default {<br>  name: &quot;Camera&quot;,<br>  components: {<br>  },<br>  data() {<br>    return {<br>      isCameraOpen: false,<br>      canvasHeight:200,<br>      canvasWidth:190,<br>      items: [],<br>    }<br>  },<br>  }</pre><pre>&lt;style scoped&gt;<br>.camera-box {<br>  border: 1px dashed #d6d6d6;<br>  border-radius: 4px;<br>  padding: 2px;<br>  width: 80%;<br>  min-height: 300px;<br>}<br> <br>&lt;/style&gt;</pre><p>The HTML file used will show the camera image button to capture the photo. Here, we are using the canvas height and width for the photo size. You can always adjust the different sizes of a photo by adjusting the canvas height and width.</p><p>Let’s use the different functions used in HTML.</p><pre>toggleCamera() {<br>      if (this.isCameraOpen) {<br>        this.isCameraOpen = false;<br>        this.stopCameraStream();<br>      } else {<br>        this.isCameraOpen = true;<br>        this.startCameraStream();<br>      }<br>    },</pre><p>This function simply toggles the camera to capture the photo. And start streaming the video. Let’s implement the function used inside this <strong><em>toggleCamer()</em></strong>.</p><pre>startCameraStream() {<br>      const constraints = (window.constraints = {<br>        audio: false,<br>        video: true<br>      });<br>      navigator.mediaDevices<br>          .getUserMedia(constraints)<br>          .then(stream =&gt; {<br>            this.$refs.camera.srcObject = stream;<br>          }).catch(error =&gt; {<br>        alert(&quot;Browser doesn&#39;t support or there is some errors.&quot; + error);<br>      });<br>    },</pre><p>The above function will start the camera by using the navigator mediaDevices interface, which will access the connected media input device, in our case, its camera. And asign the streaming to canvas dom element to show the video. Here, we are setting the constraints as <strong><em>audio is false</em></strong> because we don’t need the audio to capture the photo.</p><pre>stopCameraStream() {<br>      let tracks = this.$refs.camera.srcObject.getTracks();<br>      tracks.forEach(track =&gt; {<br>        track.stop();<br>      });<br>    },</pre><p>The above function will simply stop the camera by stopping the sequence of the track in streaming.</p><pre>capture() {<br>      const FLASH_TIMEOUT = 50;<br>      let self = this;<br>      setTimeout(() =&gt; {<br>        const context = self.$refs.canvas.getContext(&#39;2d&#39;);<br>        context.drawImage(self.$refs.camera, 0, 0, self.canvasWidth, self.canvasHeight);<br>        const dataUrl = self.$refs.canvas.toDataURL(&quot;image/jpeg&quot;)<br>            .replace(&quot;image/jpeg&quot;, &quot;image/octet-stream&quot;);<br>        self.addToPhotoGallery(dataUrl);<br>        self.uploadPhoto(dataUrl);<br>        self.isCameraOpen = false;<br>        self.stopCameraStream();<br>      }, FLASH_TIMEOUT);<br>    },</pre><p>When a user clicks the camera button, it will take the video streaming dom context and capture the 2d photo with the given width and height. We are using the setTimeout because video streaming will take some time to stream.</p><p>Let’s implement the <strong><em>self.addToPhotoGallery() is </em></strong>used in the above function. This is to preview the captured photo. For this, we are using the “<strong><em>vue-picture-swipe</em></strong>” library. So first, let’s add this to our application.</p><p>For yarn package manager:</p><pre>yarn add vue-picture-swipe</pre><p>For npm package manager:</p><pre>npm install --save vue-picture-swipe</pre><p>Import the library in our application:</p><pre>import VuePictureSwipe from &#39;vue-picture-swipe&#39;;</pre><p>Register the component:</p><pre>components: {<br>    VuePictureSwipe<br>  },</pre><p>Use in the template:</p><pre>&lt;vue-picture-swipe :items=&quot;items&quot;&gt;&lt;/vue-picture-swipe&gt;</pre><pre>addToPhotoGallery(dataURI) {<br>      this.items.push(<br>          {<br>            src: dataURI,<br>            thumbnail: dataURI,<br>            w: this.canvasWidth,<br>            h: this.canvasHeight,<br>            alt: &#39;&#39; // optional alt attribute for thumbnail image<br>          }<br>      )<br>    },</pre><p>This will preview the captured pictures.</p><p>Finally, using <strong><em>self.uploadPhoto()</em></strong> we can upload the captured picture to the server.</p><pre>uploadPhoto(dataURL){<br>      let uniquePictureName = this.generateCapturePhotoName();<br>      let capturedPhotoFile = this.dataURLtoFile(dataURL, uniquePictureName+&#39;.jpg&#39;)<br>      let formData = new FormData()<br>      formData.append(&#39;file&#39;, capturedPhotoFile)<br>      // Upload api<br>      // axios.post(&#39;http://your-url-upload&#39;, formData).then(response =&gt; {<br>      //   console.log(response)<br>      // })<br>    },<br>    generateCapturePhotoName(){<br>      return  Math.random().toString(36).substring(2, 15)<br>    },<br>    dataURLtoFile(dataURL, filename) {<br>      let arr = dataURL.split(&#39;,&#39;),<br>          mime = arr[0].match(/:(.*?);/)[1],<br>          bstr = atob(arr[1]),<br>          n = bstr.length,<br>          u8arr = new Uint8Array(n);<br> <br>      while (n--) {<br>        u8arr[n] = bstr.charCodeAt(n);<br>      }<br>      return new File([u8arr], filename, {type: mime});<br>    },</pre><p><strong><em>generateCapturePhotoName()</em></strong> will generate the unique name for each captured picture, and to send to the server, first we are converting the dataUrl value to file using <strong><em>dataURLtoFile()</em></strong>.</p><p>The overall implementation of the component <strong><em>Camera.vue</em></strong> looks like as below:</p><pre>&lt;template&gt;<br>    &lt;div class=&quot;camera-box&quot;&gt;<br>        &lt;div style=&quot;display: flex; justify-content: center;&quot;&gt;<br>            &lt;img style=&quot;height: 25px;&quot; v-if=&quot;isCameraOpen&quot;<br>                 src=&quot;https://img.icons8.com/material-outlined/50/000000/camera--v2.png&quot;<br>                 class=&quot;button-img camera-shoot&quot; @click=&quot;capture&quot;/&gt;<br>            &lt;div class=&quot;camera-button&quot;&gt;<br>                &lt;button type=&quot;button&quot; class=&quot;button is-rounded cam-button&quot;<br>                        style=&quot;margin-left: 40%; background-color: white; border: 0px;&quot;<br>                        @click=&quot;toggleCamera&quot;<br>                &gt;<br>        &lt;span v-if=&quot;!isCameraOpen&quot;&gt;&lt;img style=&quot;height: 25px;&quot; class=&quot;button-img&quot;<br>                                        src=&quot;https://img.icons8.com/material-outlined/50/000000/camera--v2.png&quot;&gt;&lt;/span&gt;<br>                    &lt;span v-else&gt;&lt;img style=&quot;height: 25px;&quot; class=&quot;button-img&quot;<br>                                      src=&quot;https://img.icons8.com/material-outlined/50/000000/cancel.png&quot;&gt;&lt;/span&gt;<br>                &lt;/button&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>        &lt;div style=&quot;height: 200px&quot;&gt;<br>            &lt;div v-if=&quot;isCameraOpen&quot; class=&quot;camera-canvas&quot;&gt;<br>                &lt;video ref=&quot;camera&quot; :width=&quot;canvasWidth&quot; :height=&quot;canvasHeight&quot; autoplay&gt;&lt;/video&gt;<br>                &lt;canvas v-show=&quot;false&quot; id=&quot;photoTaken&quot; ref=&quot;canvas&quot; :width=&quot;canvasWidth&quot; :height=&quot;canvasHeight&quot;&gt;&lt;/canvas&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>        &lt;vue-picture-swipe :items=&quot;items&quot;&gt;&lt;/vue-picture-swipe&gt;<br>    &lt;/div&gt;<br>&lt;/template&gt;<br> <br>&lt;script&gt;<br>    import VuePictureSwipe from &#39;vue-picture-swipe&#39;;<br> <br>    export default {<br>        name: &quot;Camera&quot;,<br>        components: {<br>            VuePictureSwipe<br>        },<br>        data() {<br>            return {<br>                isCameraOpen: false,<br>                canvasHeight:200,<br>                canvasWidth:190,<br>                items: [],<br>            }<br>        },<br>        methods: {<br>            toggleCamera() {<br>                if (this.isCameraOpen) {<br>                    this.isCameraOpen = false;<br>                    this.stopCameraStream();<br>                } else {<br>                    this.isCameraOpen = true;<br>                    this.startCameraStream();<br>                }<br>            },<br>            startCameraStream() {<br>                const constraints = (window.constraints = {<br>                    audio: false,<br>                    video: true<br>                });<br>                navigator.mediaDevices<br>                    .getUserMedia(constraints)<br>                    .then(stream =&gt; {<br>                        this.$refs.camera.srcObject = stream;<br>                    }).catch(error =&gt; {<br>                    alert(&quot;Browser doesn&#39;t support or there is some errors.&quot; + error);<br>                });<br>            },<br> <br>            stopCameraStream() {<br>                let tracks = this.$refs.camera.srcObject.getTracks();<br>                tracks.forEach(track =&gt; {<br>                    track.stop();<br>                });<br>            },<br> <br>            capture() {<br>                const FLASH_TIMEOUT = 50;<br>                let self = this;<br>                setTimeout(() =&gt; {<br>                    const context = self.$refs.canvas.getContext(&#39;2d&#39;);<br>                    context.drawImage(self.$refs.camera, 0, 0, self.canvasWidth, self.canvasHeight);<br>                    const dataUrl = self.$refs.canvas.toDataURL(&quot;image/jpeg&quot;)<br>                        .replace(&quot;image/jpeg&quot;, &quot;image/octet-stream&quot;);<br>                    self.addToPhotoGallery(dataUrl);<br>                    self.uploadPhoto(dataUrl);<br>                    self.isCameraOpen = false;<br>                    self.stopCameraStream();<br>                }, FLASH_TIMEOUT);<br>            },<br> <br>            addToPhotoGallery(dataURI) {<br>                this.items.push(<br>                    {<br>                        src: dataURI,<br>                        thumbnail: dataURI,<br>                        w: this.canvasWidth,<br>                        h: this.canvasHeight,<br>                        alt: &#39;some numbers on a grey background&#39; // optional alt attribute for thumbnail image<br>                    }<br>                )<br>            },<br>            uploadPhoto(dataURL){<br>                let uniquePictureName = this.generateCapturePhotoName();<br>                let capturedPhotoFile = this.dataURLtoFile(dataURL, uniquePictureName+&#39;.jpg&#39;)<br>                let formData = new FormData()<br>                formData.append(&#39;file&#39;, capturedPhotoFile)<br>                // Upload image api<br>                // axios.post(&#39;http://your-url-upload&#39;, formData).then(response =&gt; {<br>                //   console.log(response)<br>                // })<br>            },<br> <br>            generateCapturePhotoName(){<br>                return  Math.random().toString(36).substring(2, 15)<br>            },<br> <br>            dataURLtoFile(dataURL, filename) {<br>                let arr = dataURL.split(&#39;,&#39;),<br>                    mime = arr[0].match(/:(.*?);/)[1],<br>                    bstr = atob(arr[1]),<br>                    n = bstr.length,<br>                    u8arr = new Uint8Array(n);<br> <br>                while (n--) {<br>                    u8arr[n] = bstr.charCodeAt(n);<br>                }<br>                return new File([u8arr], filename, {type: mime});<br>            },<br>        }<br>    }<br>&lt;/script&gt;<br> <br>&lt;style scoped&gt;<br>    .camera-box {<br>        border: 1px dashed #d6d6d6;<br>        border-radius: 4px;<br>        padding: 2px;<br>        width: 80%;<br>        min-height: 300px;<br>    }<br> <br>&lt;/style&gt;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=229c63b6dfa6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/360learntocode/how-to-implement-webcam-in-vuejs-application-229c63b6dfa6">How to Implement Webcam in VueJs Application</a> was originally published in <a href="https://medium.com/360learntocode">360learntocode</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build the Vuejs Application as a Library and Web Component]]></title>
            <link>https://medium.com/360learntocode/how-to-build-the-vuejs-application-as-a-library-and-web-component-f25808612673?source=rss----f0254769325f---4</link>
            <guid isPermaLink="false">https://medium.com/p/f25808612673</guid>
            <category><![CDATA[lib]]></category>
            <category><![CDATA[web-components]]></category>
            <category><![CDATA[vue-3]]></category>
            <category><![CDATA[nuxtjs]]></category>
            <category><![CDATA[vue]]></category>
            <dc:creator><![CDATA[kumar chapagain]]></dc:creator>
            <pubDate>Thu, 20 Mar 2025 05:36:44 GMT</pubDate>
            <atom:updated>2025-03-20T05:36:44.805Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial, we are going to learn how to create a library and a web component of the Vuejs application so that we can reuse them as a library in a different application and as a custom HTML element on different web pages.</p><p>Using VueCli 3.x it’s very easy to build our application. It gives some commands to create them.</p><p><strong>1. Create a sample Vuejs application:</strong></p><p>Open the command prompt or terminal and use the following command:</p><pre>vue create vue-build-target-app</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/0*joDHzKmbO7T2FKcq.PNG" /></figure><p>You can either select the <strong>Default</strong> option so that you don’t manually setup. This will default use the yarn package manager so, make sure to have package manager installed. Also, you can manually select the features option.</p><p>Now, go to the project directory and run the application using the command:</p><pre>cd vue-build-target-app<br>yarn serve</pre><p>If you open the project, you can see the default component called HelloWorld.vue. We are using the same component to test.</p><p><strong>2. Build as a Library:</strong></p><p><strong>Note: <em>In lib mode, Vue is externalized. This means the bundle will not bundle Vue even if your code imports Vue</em></strong></p><p>While building as a library even if we are importing the Vue in the component it will not use that in the bundle.</p><p>Building a single component as a library:</p><pre>vue-cli-service build --target lib --name myLib [entry]</pre><p>This is the command that we use where <em>myLib</em> is the name of the output bundle file and <em>[entry]</em> is the entity that we use.</p><p>For e.g:</p><pre>vue-cli-service build --target lib --name HelloWorld src/components/HelloWorld.vue</pre><p>This will build the single component HelloWorld.vue as the library. So, what you need to do is place the above command inside the <strong><em>package.json</em></strong> file under <strong><em>scripts</em></strong>.</p><pre>&quot;build-lib&quot;: &quot;vue-cli-service build --target lib --name HelloWorld src/components/HelloWorld.vue&quot;,</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*FAYenZUlKZy-qJhv.PNG" /></figure><p>Now, run the script from the command prompt:</p><pre>yarn build-lib</pre><p>This command will build the target files inside <strong><em>dis</em></strong> folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/0*qDhWbVeQNo5cBotN.PNG" /></figure><p><strong><em>dist\HelloWorld.umd.js </em></strong>is the UMD bundle that can be served in the normal HTML file. As you can see the sample use case inside the dist folder contains the following <strong><em>demo.html</em></strong> file:</p><pre>&lt;meta charset=&quot;utf-8&quot;&gt;&lt;/meta&gt;<br>&lt;title&gt;HelloWorld demo&lt;/title&gt;<br>&lt;script src=&quot;https://unpkg.com/vue&quot;&gt;&lt;/script&gt;<br>&lt;script src=&quot;./HelloWorld.umd.js&quot;&gt;&lt;/script&gt;<br> <br> &lt;link href=&quot;./HelloWorld.css&quot; rel=&quot;stylesheet&quot;&gt; &lt;/link&gt;<br> <br> <br>&lt;div id=&quot;app&quot;&gt;<br>  &lt;demo&gt;  &lt;/demo&gt;<br>&lt;/div&gt;<br> <br>&lt;script&gt;<br>new Vue({<br>  components: {<br>    demo: HelloWorld<br>  }<br>}).$mount(&#39;#app&#39;)<br>&lt;/script&gt;</pre><p>If you run this HTML file then you can see the desired output for that page.</p><p><strong><em>dist\HelloWorld.umd.min.js</em></strong> is the minified version of the UMD bundle</p><p><strong><em>dist\HelloWorld.common.js</em></strong> is used in a module-based application</p><p><strong><em>dist\HelloWorld.css</em></strong> is the CSS file that is associated with that component.</p><p>You can use those desired files on your web pages.</p><p><strong>3. Build as a Web Component:</strong></p><p>You can build a single entry as:</p><pre>vue-cli-service build --target wc --name my-element [entry]</pre><p>Here wc will build as a web component. For e.g:</p><pre>vue-cli-service build --target wc -name HelloWorld src/components/HelloWorld.vue</pre><p>Use this inside script and run the command:</p><pre>&quot;build-wc&quot;:vue-cli-service build --target wc -name HelloWorld src/components/HelloWorld.vue</pre><p>Here you can give any name instead of “build-wc” but you need to run the build command with this name</p><pre>yarn build-wc</pre><p>Which will create the following files under the <strong><em>dist</em></strong> folder:</p><p><strong><em>dist\hello-world.js</em></strong></p><p><strong><em>dist\hello-world.min.js</em></strong></p><p>This is the web pack bundle that can be used on web pages. Sample example is created under the same folder i.e. <strong><em>demo.html</em></strong>.</p><p>This doesn’t require component registration, as the component is already registered while creating it. So it looks like a normal plain HTML element.</p><p>If you want to build the multiple components file then use the following command instead:</p><pre>//package.json<br>    &quot;build-wc&quot;: &quot;vue-cli-service build --target wc --name demo src/components/*.vue&quot;,</pre><p>Video: <a href="https://youtu.be/tge4W8MeJeM">https://youtu.be/tge4W8MeJeM</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f25808612673" width="1" height="1" alt=""><hr><p><a href="https://medium.com/360learntocode/how-to-build-the-vuejs-application-as-a-library-and-web-component-f25808612673">How to Build the Vuejs Application as a Library and Web Component</a> was originally published in <a href="https://medium.com/360learntocode">360learntocode</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Example to Test Whether String is Null or Empty in Java]]></title>
            <link>https://medium.com/360learntocode/example-to-test-whether-string-is-null-or-empty-in-java-7091166b2ace?source=rss----f0254769325f---4</link>
            <guid isPermaLink="false">https://medium.com/p/7091166b2ace</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[null]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[string]]></category>
            <dc:creator><![CDATA[kumar chapagain]]></dc:creator>
            <pubDate>Mon, 10 Mar 2025 10:03:00 GMT</pubDate>
            <atom:updated>2025-03-10T10:03:00.302Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>This is a short tutorial to test whether the given string is null or empty.</strong></p><p>Let’s look at the following example:</p><pre>public class StringUtil {<br>    public static void main(String[] args) {<br>        String nonEmptyString = &quot;non empty string&quot;;<br>        String nullString = null;<br>        String emptyString = &quot;&quot;;<br>        String emptyStringWithWhiteSpace = &quot; &quot;;<br>        boolean isNonEmpty = isNullOrEmpty(nonEmptyString);<br>        System.out.println(isNonEmpty); //false<br>        boolean isNullString = isNullOrEmpty(nullString);<br>        System.out.println(isNullString); //true<br>        boolean isEmptyString = isNullOrEmpty(emptyString);<br>        System.out.println(isEmptyString); //true<br>        boolean isEmptyStringWithWhiteSpace = isNullOrEmpty(emptyStringWithWhiteSpace);<br>        System.out.println(isEmptyStringWithWhiteSpace); //true<br>    }<br> <br>    private static boolean isNullOrEmpty(String str) {<br>        if(str == null || str.trim().isEmpty())<br>            return true;<br>        return false;<br>    }<br> <br>}</pre><p>Here, we are using different types of string values to test whether it is null or empty. In order to test we are simply creating the isNullOrEmpty(String str) method, which will return true if the string is null or empty and false if it is not. If the first condition is satisfied it will not test the second one because we are using OR logic. So, even if the “str” is null it will not throw an error.</p><p>The reason behind using trim() is to remove any leading or trailing white space from the given string. So the isEmpty() method will not consider the empty string with white space as a non-empty string.</p><p>Basically, isEmpty() will test the length of the string to return the boolean value. So, if the given string contains white space, even if the string is empty it will return false.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7091166b2ace" width="1" height="1" alt=""><hr><p><a href="https://medium.com/360learntocode/example-to-test-whether-string-is-null-or-empty-in-java-7091166b2ace">Example to Test Whether String is Null or Empty in Java</a> was originally published in <a href="https://medium.com/360learntocode">360learntocode</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create a List of String to Comma Separated String]]></title>
            <link>https://medium.com/360learntocode/how-to-create-a-list-of-string-to-comma-separated-string-055dc0ec9ed4?source=rss----f0254769325f---4</link>
            <guid isPermaLink="false">https://medium.com/p/055dc0ec9ed4</guid>
            <category><![CDATA[java8]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[string]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[kumar chapagain]]></dc:creator>
            <pubDate>Mon, 10 Mar 2025 09:58:47 GMT</pubDate>
            <atom:updated>2025-03-10T09:58:46.964Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>This is a short tutorial to show how to convert the list of strings into a comma-separated string.</strong></p><p><strong>1. In Java 8 and later:</strong></p><ul><li>Using String.join()<strong> </strong>method.</li></ul><pre> import java.util.Arrays;<br>import java.util.List;<br> <br>public class JavaStringJoin {<br>    public static void main(String[] args) {<br>        List &lt;String&gt; stringList = Arrays.asList(&quot;apple&quot;,&quot;banana&quot;,&quot;grapes&quot;);<br>        String joinedString = String.join(&quot;,&quot;, stringList);<br>        System.out.println(joinedString);<br>    }<br>}</pre><p><strong>Output:</strong></p><pre>apple,banana,grapes</pre><p>This will simply join each element of the list with the delimiter provided. Here, we are providing “,” as a delimiter. If the element present in the list is null then it will join the “null” to the string. If the delimiter is null then, it will throw a Null Pointer Exception.</p><ul><li><strong>Using stream API:</strong></li></ul><pre>import java.util.Arrays;<br>import java.util.List;<br>import java.util.stream.Collectors;<br> <br>public class JavaStringJoin {<br>    public static void main(String[] args) {<br>        List &lt;String&gt; stringList = Arrays.asList(&quot;apple&quot;,&quot;banana&quot;,&quot;grapes&quot;);<br>        String joinedString = stringList.stream().collect(Collectors.joining(&quot;,&quot;));<br>        System.out.println(joinedString);<br>    }<br>}</pre><ul><li><strong>Using StringJoiner:</strong></li></ul><pre>import java.util.Arrays;<br>import java.util.List;<br>import java.util.StringJoiner;<br> <br>public class JavaStringJoin {<br>    public static void main(String[] args) {<br>        List &lt;String&gt; stringList = Arrays.asList(&quot;apple&quot;,&quot;banana&quot;,&quot;grapes&quot;);<br>        StringJoiner stringJoiner = new StringJoiner(&quot;,&quot;);<br>        for (String element : stringList){<br>            stringJoiner.add(element);<br>        }<br>        System.out.println(stringJoiner.toString());<br>    }<br>}</pre><p>Actually, String.join() uses this StringJoiner mechanism.</p><p>The output will be the same as the previous example.</p><p><strong>2. You can use StringBuilder to build the concatenated string:</strong></p><pre>import java.util.Arrays;<br>import java.util.List;<br> <br>public class JavaStringJoin {<br>    public static void main(String[] args) {<br>        List &lt;String&gt; stringList = Arrays.asList(&quot;apple&quot;,&quot;banana&quot;,&quot;grapes&quot;);<br>        StringBuilder stringBuilder = new StringBuilder();<br>        int size = stringList.size();<br>        for (int i = 0; i &lt; size; i++) {<br>            stringBuilder.append(stringList.get(i));<br>            if (i &lt; size -1){<br>                stringBuilder.append(&quot;,&quot;);<br>            }<br>        }<br>        System.out.println(stringBuilder.toString());<br>    }<br>}</pre><p><strong>3. If you are using Apache’s commons library, you can use StringUtils.join() method.</strong></p><pre>String joinedString = StringUtils.join(stringList, &quot;,&quot;)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=055dc0ec9ed4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/360learntocode/how-to-create-a-list-of-string-to-comma-separated-string-055dc0ec9ed4">How to Create a List of String to Comma Separated String</a> was originally published in <a href="https://medium.com/360learntocode">360learntocode</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Convert Tiff file to JPG/PNG using Java.]]></title>
            <link>https://medium.com/360learntocode/convert-tiff-file-to-jpg-png-using-java-d0ba1f304ea3?source=rss----f0254769325f---4</link>
            <guid isPermaLink="false">https://medium.com/p/d0ba1f304ea3</guid>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[image]]></category>
            <category><![CDATA[tiff]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[kumar chapagain]]></dc:creator>
            <pubDate>Mon, 10 Mar 2025 05:55:37 GMT</pubDate>
            <atom:updated>2025-03-10T05:55:37.569Z</atom:updated>
            <content:encoded><![CDATA[<p>While dealing with the tiff file, we may have the problem that some browsers don’t support it. Please visit for image format support for different browsers <a href="https://en.wikipedia.org/wiki/Comparison_of_web_browsers#Image_format_support">here</a>. In this tutorial, we are going to convert the tiff file to a jpg or png file format in an efficient way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/0*RndU0nJHlqh5zt2p" /></figure><p><strong>Dependencies required:</strong></p><p>In order to convert tiff to other image formats, we are using Jai image i/o library. Download the jar file from <a href="https://github.com/jai-imageio/jai-imageio-core/releases">here</a>. As we are using lib version “jai-imageio-core-1.4.0” <a href="https://github.com/jai-imageio/jai-imageio-core/releases/tag/jai-imageio-core-1.4.0">here</a>, you can find the jar file under Assets. Load the jar file in your IDE or if you have existing projects like Maven or Gradle add the dependency as below.</p><p><strong>For Gradle:</strong></p><p>Add in <strong>build.gradle </strong>under “dependencies”</p><pre>compile &#39;com.github.jai-imageio:jai-imageio-core:1.4.0&#39;</pre><p><strong>For Maven:</strong></p><p>Add in pom.xml</p><pre>&lt;dependencies&gt;<br>    &lt;dependency&gt;<br>        &lt;groupid&gt;com.github.jai-imageio&lt;/groupid&gt;<br>        &lt;artifactid&gt;jai-imageio-core&lt;/artifactid&gt;<br>        &lt;version&gt;1.4.0&lt;/version&gt;<br>    &lt;/dependency&gt;<br>&lt;/dependencies&gt;</pre><p><strong>Convert Tiff to PNG/JPG</strong></p><p>Let’s create a class called “TiffConverter.java”</p><p><strong>TiffConverter.java:</strong></p><pre>public static void main(String[] args) {<br>        File tiffFile = new File(&quot;/home/360learntocode/im.tif&quot;); //input path to tif file<br>        String outputPath = &quot;/home/360learntocode/&quot;; //output path to write file<br>        String convertFormat = &quot;jpg&quot;; //jpg, png, bmp<br>        try {<br>            TiffConverter.convertTiff(tiffFile, outputPath, convertFormat);<br>        } catch (IOException e) {<br>            e.printStackTrace();<br>        }<br>    }</pre><p>Provide the appropriate input and output path. You can provide the desired conversion format. The conversion will reduce the pixel value of the image for jpg, and png although BMP conversion doesn’t reduce the pixel value.</p><pre>private static File convertTiff(File tiffFile, String outputPath, String convertFormat) throws IOException {<br>        String fileName = tiffFile.getName();<br>        String ext = getFileExtension(fileName);<br>        fileName = fileName.replace(ext, &quot;.&quot;+convertFormat);<br>        BufferedImage tiff = ImageIO.read(tiffFile);<br>        File output = new File(outputPath + fileName);<br>        ImageIO.write(tiff, convertFormat, output);<br>        return output;<br>    }</pre><p>We are using the library to manipulate and convert the TIF file. BufferedImage is used to handle and manipulate the image data. For more visit <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/java/awt/image/BufferedImage.html">here</a>.</p><pre> <br>  //get file extension from file name<br>    private static String getFileExtension(String fileName) {<br>        int lastIndexOf = fileName.lastIndexOf(&quot;.&quot;);<br>        return fileName.substring(lastIndexOf).toLowerCase();<br>    }</pre><p>Finally, we successfully converted the Tiff/Tif File to the desired format like jpg, png, or BMP.</p><p>The overall implementation looks like as below:</p><pre> import javax.imageio.ImageIO;<br>import java.awt.image.BufferedImage;<br>import java.io.File;<br>import java.io.IOException;<br> <br> <br>public class TiffConverter {<br> <br>    public static void main(String[] args) {<br>        File tiffFile = new File(&quot;/home/360learntocode/im.tif&quot;); //input path to tif file<br>        String outputPath = &quot;/home/360learntocode/&quot;; //output path to write file<br>        String convertFormat = &quot;jpg&quot;; //jpg, png, bmp<br>        try {<br>            TiffConverter.convertTiff(tiffFile, outputPath, convertFormat);<br>        } catch (IOException e) {<br>            e.printStackTrace();<br>        }<br>    }<br> <br>    private static File convertTiff(File tiffFile, String outputPath, String convertFormat) throws IOException {<br>        String fileName = tiffFile.getName();<br>        String ext = getFileExtension(fileName);<br>        fileName = fileName.replace(ext, &quot;.&quot;+convertFormat);<br>        BufferedImage tiff = ImageIO.read(tiffFile);<br>        File output = new File(outputPath + fileName);<br>        ImageIO.write(tiff, convertFormat, output);<br>        return output;<br>    }<br> <br>    //get file extension from file name<br>    private static String getFileExtension(String fileName) {<br>        int lastIndexOf = fileName.lastIndexOf(&quot;.&quot;);<br>        return fileName.substring(lastIndexOf).toLowerCase();<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0ba1f304ea3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/360learntocode/convert-tiff-file-to-jpg-png-using-java-d0ba1f304ea3">Convert Tiff file to JPG/PNG using Java.</a> was originally published in <a href="https://medium.com/360learntocode">360learntocode</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>