<?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[Stories by Md. Kanok Hossain on Medium]]></title>
        <description><![CDATA[Stories by Md. Kanok Hossain on Medium]]></description>
        <link>https://medium.com/@kanokHossain?source=rss-3d9138b88ba1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-CuJ4zWL-GHrf0Dd3sUWjg.jpeg</url>
            <title>Stories by Md. Kanok Hossain on Medium</title>
            <link>https://medium.com/@kanokHossain?source=rss-3d9138b88ba1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 01:28:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kanokHossain/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ Dockerize Your Frontend Like a Pro: The Ultimate Setup Guide]]></title>
            <link>https://medium.com/@kanokHossain/dockerize-your-frontend-like-a-pro-the-ultimate-setup-guide-573dc011b854?source=rss-3d9138b88ba1------2</link>
            <guid isPermaLink="false">https://medium.com/p/573dc011b854</guid>
            <dc:creator><![CDATA[Md. Kanok Hossain]]></dc:creator>
            <pubDate>Wed, 07 May 2025 09:08:47 GMT</pubDate>
            <atom:updated>2025-05-08T08:36:02.352Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Note:</strong> This guide assumes you have some basic knowledge of Docker. If you’re just starting out, consider reviewing Docker’s official <a href="https://www.docker.com/get-started/">documentation</a> or introductory tutorials to get familiar with the concepts of images, containers, and Docker Compose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6p_DRB73zqiWHQg_KRUCxg.png" /></figure><p>Dockerizing frontend apps should make life easier — not harder, here’s the <strong>cleanest, most reliable Docker setup</strong> for modern frontend development. It works out of the box with frameworks like <strong>Vite</strong>, <strong>React</strong>, <strong>Vue</strong>, or <strong>Next.js</strong>. Let’s make your dev environment fast, consistent, and production-like.</p><h3>🌟 Why Docker for Frontend Development?</h3><p><strong>Without Docker:</strong></p><ul><li>“It works on my machine” issues.</li><li>Messy Node.js versions and mismatched dependencies.</li><li>Hard to share exact dev environments across teams.</li></ul><p><strong>With Docker:</strong></p><ul><li><strong>Consistency</strong> — Same setup across all machines.</li><li><strong>Isolation</strong> — No local dependencies polluting your system.</li><li><strong>Custom domains(optional)</strong> — Mimic production-like environments easily.</li><li><strong>Fast onboarding</strong> — Team members run docker compose up and start coding.</li></ul><h3>📚 To Know More</h3><ul><li><a href="https://mottr1.medium.com/frontend-development-and-docker-whats-the-relation-2dc894bb0db7">Frontend Development and Docker: What’s the Relation? (by Mottr1)</a></li><li><a href="https://materokatti.medium.com/grasping-docker-a-front-end-developers-perspective-80c0dd64ec18">Grasping Docker: A Front-End Developer’s Perspective (by Materokatti)</a></li></ul><h3>🎯 AIM of This Blog</h3><p>This blog aims to solve the “it works on my machine” issue by ensuring all developers use the <strong>same Node.js version</strong> (Node 18.20.5) through Docker. It creates a consistent, isolated environment for all team members, eliminating setup inconsistencies across different machines.</p><h3>Key Benefit: Unified Node.js Version</h3><p>Docker ensures every developer works with the <strong>same Node.js version</strong>, preventing issues that arise from version mismatches, regardless of their local environment.</p><h3>Why It Matters:</h3><ol><li><strong>Consistency</strong>: No more version-related conflicts.</li><li><strong>Quick Setup</strong>: New contributors can start instantly with docker compose up.</li><li><strong>Environment Stability</strong>: Docker abstracts local setup, keeping the environment consistent across all machines.</li></ol><h3>⚡ Example: Node.js Version Compatibility Issue</h3><p>The <strong>structuredClone()</strong> function is supported in <strong>Node.js 17+</strong> but not in earlier versions. Without Docker, developers using different versions could face issues.</p><h4>Code Example:</h4><pre>// Node.js 17+ works<br>const clonedObj = structuredClone(obj);</pre><pre>// In older versions, throws an error<br>// structuredClone is not defined</pre><h3>Takeaway:</h3><ul><li>Docker guarantees the same Node.js version for everyone, ensuring compatibility.</li></ul><p><strong>What could happen without Docker:</strong></p><ul><li>If a developer works on their machine with Node.js 18 and uses the structuredClone() function, it would work fine locally. However, if the production environment is running Node.js 16 (which doesn&#39;t support structuredClone()), the code will break when deployed. This discrepancy could lead to hard-to-debug issues, especially if the developer is unaware of the version difference. Docker prevents this by ensuring that the same version of Node.js (e.g., Node 16 in this case) is used consistently across development, staging, and production environments, avoiding these types of issues.</li></ul><h3><strong>🛠️ What You’ll Build In This Blog</strong></h3><p>A Docker-powered frontend dev setup with:</p><ul><li>Node.js <strong>18.20.5</strong> (official image)</li><li><strong>Vite dev server</strong> (with hot-reload)</li><li>Access via custom domain <a href="http://local.frontend.app:5173/">http://local.frontend.app:5173</a></li></ul><h3>⚡ Quick Start (For Impatient Devs)</h3><pre># .dockerignore<br>node_modules<br>dist<br>.env*<br>.npmrc<br>.vscode<br>.DS_Store<br>.git</pre><pre># Dockerfile<br>FROM node:18.20.5<br>WORKDIR /app<br>COPY package*.json ./<br>COPY .npmrc.local .npmrc<br>RUN npm install &amp;&amp; rm -f .npmrc<br>COPY . .<br>EXPOSE 5173<br>CMD [&quot;npm&quot;, &quot;run&quot;, &quot;dev&quot;, &quot;--&quot;, &quot;--host&quot;]</pre><pre># docker-compose.yml<br>version: &quot;3.9&quot;<br>services:<br>  frontend-app:<br>    image: frontend-app<br>    container_name: frontend-app<br>    build: .<br>    ports:<br>      - &quot;5173:5173&quot;<br>    env_file:<br>      - .env.development.local<br>    volumes:<br>      - .:/app<br>      - /app/node_modules<br>    command: npm run dev -- --host<br>    extra_hosts:<br>      - &quot;local.frontend.app:127.0.0.1&quot;</pre><h3>🧐 Line-by-Line Deep Dive (Why We Use What)</h3><h3>📄 .dockerignore</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ZpVEj4eVhP0uHhDNq-N1A.png" /></figure><h3>📄 Dockerfile</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qBKZWoP-Pi41IP11UcM8SQ.png" /></figure><h3>📄 docker-compose.yml</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EE7U8feNII1-HguaQrv__w.png" /></figure><h3>🌐 Setting Up the Custom Domain (Optional but Powerful)</h3><p>Edit your /etc/hosts (Linux/Mac) or C:\Windows\System32\drivers\etc\hosts (Windows):</p><pre>127.0.0.1 local.frontend.app</pre><blockquote><em>💡 </em><strong><em>Why custom domain?</em></strong></blockquote><ul><li>Test SameSite cookie behavior (modern browsers treat localhost differently)</li><li>Avoid port conflicts</li><li>Consistent URLs for teams</li></ul><h3>▶️ How to Build &amp; Run</h3><ol><li><strong>Build the image:</strong></li></ol><pre>docker build -t frontend-app.</pre><p><strong>2. Run the dev environment:</strong></p><pre>docker compose up</pre><p><strong>3. Access your app:</strong></p><pre>http://local.frontend.app:5173</pre><p><strong>4. Stop containers:</strong></p><pre>docker compose down</pre><h3>🎉 Wrap-Up</h3><p>Congrats — you now have a <strong>fast, reliable Docker frontend environment</strong>:</p><ul><li>Clean dev workflow</li><li>Team-friendly setup</li><li>Production-like testing</li></ul><p>By setting up Docker, we’ve seen how Node.js versions can be aligned across all environments, ensuring consistency. You can use this same setup to align other dependencies as well, eliminating conflicts between local and production setups.</p><h3>💬 Let’s Chat!</h3><p>Got questions? Drop a comment below.<br> Found this useful? <strong>Clap, bookmark, and share</strong> with your team 🚀</p><p>🔗 <a href="https://github.com/kanokHossain">GitHub</a> | 🔗 <a href="https://www.linkedin.com/in/kanokhossain/">LinkedIn</a></p><p>Collaborator: <a href="https://www.linkedin.com/in/faizul-islam/">Faizul Islam</a></p><p>If you want to know anything further or want us to deep dive even more — let us know! We might bring <strong>Part 2</strong> just for you. 😉</p><p>Happy coding! ✨</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=573dc011b854" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Postmortem: Reactivity Utilities in Vue.js with Real-Life Examples]]></title>
            <link>https://medium.com/@kanokHossain/postmortem-reactivity-utilities-in-vue-js-with-real-life-examples-0e2d0d0d96de?source=rss-3d9138b88ba1------2</link>
            <guid isPermaLink="false">https://medium.com/p/0e2d0d0d96de</guid>
            <category><![CDATA[vue-js-developer]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[vue-js-online-course]]></category>
            <category><![CDATA[vue-composition-api]]></category>
            <category><![CDATA[vue-js-app-development]]></category>
            <dc:creator><![CDATA[Md. Kanok Hossain]]></dc:creator>
            <pubDate>Sat, 25 Jan 2025 15:22:57 GMT</pubDate>
            <atom:updated>2025-01-25T15:45:37.161Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xdgb5bWMsvpXloJejhNSBg.png" /></figure><p>Vue.js reactivity system is a cornerstone of its declarative programming model. While working with reactivity utilities like isRef(), unref(), toRef(), and others, developers often find themselves puzzled by their nuances. In this postmortem, we’ll explore these utilities, dissect their use cases, and demonstrate them with detailed, relatable real-life examples.</p><h3>1. What is Reactivity in Vue.js?</h3><p>At its core, Vue’s reactivity system allows your UI to automatically update when your data changes. This makes the development process seamless. Vue achieves this through a proxy-based reactivity system. Utilities like isRef, toRefs, and isReactive are tools to help interact with and manipulate reactive data efficiently.</p><p>Let’s break down each utility and its purpose.</p><h3>2. Understanding the Utilities</h3><h3>2.1 isRef()</h3><p>The isRef() utility checks if a given value is a reactive reference.</p><h4>Real-Life Function Example:</h4><p>Imagine a fitness tracking app where users can set and modify their workout goals, like the number of steps per day. The app differentiates between user-defined reactive goals and default static values provided by the app.</p><pre>import { ref, isRef } from &#39;vue&#39;;</pre><pre>// Reactive user-defined step goal<br>const userStepGoal = ref(10000);</pre><pre>// Static default step goal<br>const defaultStepGoal = 8000;</pre><pre>// Function to check goal type<br>function displayGoalType(goal) {<br>  return isRef(goal)<br>    ? `This goal is reactive. Current value: ${goal.value}`<br>    : `This goal is static. Value: ${goal}`;<br>}</pre><pre>// Example usage<br>console.log(displayGoalType(userStepGoal)); // Output: This goal is reactive. Current value: 10000<br>console.log(displayGoalType(defaultStepGoal)); // Output: This goal is static. Value: 8000</pre><p><em>Scenario:</em> In this fitness app, when users modify their step goal via a settings page, the reactive goal automatically updates the dashboard’s progress bar and statistics, while static default goals remain fixed. By using isRef, the app can efficiently distinguish between dynamic and static goals.</p><h3>2.2 unref()</h3><p>The unref() function returns the inner value of a ref. If the value is not a ref, it returns it as-is.</p><h4>Real-Life Function Example:</h4><p>Imagine a logistics app where you track the delivery status of orders. The status could either be dynamically updated from an API (reactive) or a static default fallback in case of network issues. A function calculates the display status based on these inputs.</p><pre>import { ref, unref } from &#39;vue&#39;;</pre><pre>// Reactive status fetched from API<br>const liveStatus = ref(&#39;In Transit&#39;);</pre><pre>// Static fallback status<br>const fallbackStatus = &#39;Pending&#39;;</pre><pre>// Function to determine current status<br>function getDisplayStatus(status) {<br>  return `Current Status: ${unref(status)}`;<br>}</pre><pre>// Example usage<br>console.log(getDisplayStatus(liveStatus)); // Output: Current Status: In Transit<br>console.log(getDisplayStatus(fallbackStatus)); // Output: Current Status: Pending</pre><p><em>Scenario:</em> In the logistics app, the getDisplayStatus function ensures that the UI consistently displays the correct order status, regardless of whether it&#39;s coming from the live API or a predefined static value.</p><h3>2.3 toRef()</h3><p>toRef() creates a ref from a specific property of a reactive object.</p><h4>Real-Life Function Example:</h4><p>In a project management tool, you have a reactive object representing a task. You want to bind the priority property to a dropdown menu without unwrapping the entire object.</p><pre>import { reactive, toRef } from &#39;vue&#39;;</pre><pre>const task = reactive({<br>  title: &#39;Fix Bug&#39;,<br>  priority: &#39;High&#39;<br>});</pre><pre>const taskPriority = toRef(task, &#39;priority&#39;);</pre><pre>console.log(taskPriority.value); // &#39;High&#39;</pre><pre>taskPriority.value = &#39;Low&#39;;<br>console.log(task.priority); // &#39;Low&#39;</pre><p><em>Scenario:</em> In a Kanban board, tasks are reactive objects with multiple properties like status, priority, and assignee. When implementing an inline editor for task priority, toRef allows you to bind only the priority property to the editor, keeping the rest of the task intact and reactive.</p><h3>2.4 toValue()</h3><h3>Why Use toValue():</h3><ul><li><strong>Simplifies Mixed Data</strong>: No need to check if the value is a ref, static, or computed. toValue() normalizes everything to a value, making the logic easier.</li><li><strong>Handles Getters</strong>: toValue() will invoke computed properties (getters) and return their result, unlike unref(), which only works for refs.</li></ul><h4>Real-Life Function Example:</h4><p>Imagine you are running a restaurant management system that handles table reservations. The reservation fee might be dynamic (reactive, based on peak hours) or static (flat rate). You want to calculate the total reservation cost by adding a service fee.</p><pre>import { ref, computed, toValue } from &#39;vue&#39;;</pre><pre>// Reservation fees<br>const peakHourFee = ref(50); // Reactive fee<br>const flatFee = 30;          // Static fee</pre><pre>// Service fee<br>const serviceFee = 10;</pre><pre>// Computed property (getter) for dynamic discount<br>const discount = computed(() =&gt; {<br>  // Dynamic discount based on certain conditions (e.g., promotions or time of day)<br>  const currentHour = new Date().getHours();<br>  return currentHour &gt;= 18 &amp;&amp; currentHour &lt;= 22 ? 5 : 0; // Discount during peak dinner hours<br>});</pre><pre>// Function to calculate total cost<br>function calculateReservationCost(fee) {<br>  // `toValue()` will handle refs, static values, and computed getters<br>  return toValue(fee) + toValue(discount) + serviceFee;<br>}</pre><pre>// Example usage<br>console.log(calculateReservationCost(peakHourFee));   // Output: 60 (50 + 10 service fee + dynamic discount of 0 or 5)<br>console.log(calculateReservationCost(flatFee));       // Output: 40 (30 + 10 service fee + dynamic discount of 0 or 5)<br>console.log(calculateReservationCost(discount));     // Output: 15 (0 discount if outside peak hours, + service fee)</pre><h3>Conclusion:</h3><ul><li><strong>toValue()</strong> makes your function more flexible by handling different types of reactive data (like ref, computed) and static values in a simple, unified way. You don’t need to manually handle each case, which simplifies your code.</li></ul><h3>2.5 toRefs()</h3><p>toRefs() converts all properties of a reactive object into refs.</p><h4>Real-Life Function Example:</h4><p>In an online store, you might have a reactive object for a product’s details. To bind specific properties like price and availability to UI components, use toRefs().</p><pre>import { reactive, toRefs } from &#39;vue&#39;;</pre><pre>const product = reactive({<br>  name: &#39;Laptop&#39;,<br>  price: 1200,<br>  inStock: true<br>});</pre><pre>const { name, price, inStock } = toRefs(product);</pre><pre>console.log(name.value); // &#39;Laptop&#39;</pre><pre>name.value = &#39;Gaming Laptop&#39;;<br>console.log(product.name); // &#39;Gaming Laptop&#39;</pre><p><em>Scenario:</em> For an admin dashboard, you want inline editing for product properties. Using toRefs, you can bind individual properties to different form inputs without disrupting the reactivity of the original product object.</p><h3>2.6 isProxy()</h3><p>In Vue.js, isProxy() is a utility function that checks whether an object is a reactive proxy, created by one of the following methods: reactive(), readonly(), shallowReactive(), or shallowReadonly(). This is useful for determining the reactivity state of an object in your application, which can help guide your logic for modifying or displaying data.</p><h4>Real-Life Scenario</h4><p>Imagine you’re building an e-commerce platform where customers can customize products, like laptops. Product data can either be <strong>reactive</strong> (allowing dynamic changes during customization) or <strong>readonly</strong> (showing pre-configured templates). You want to ensure that customers can only modify <strong>reactive</strong> product data and not the readonly templates.</p><p>This is where isProxy() comes into play. By checking if an object is a proxy (created by reactive(), readonly(), shallowReactive(), or shallowReadonly()), you can implement conditional logic for customization features.</p><h4>Example Code</h4><pre>import { reactive, readonly, isProxy } from &#39;vue&#39;;</pre><pre>// Reactive product data<br>const customizableProduct = reactive({<br>  name: &#39;Laptop&#39;,<br>  configuration: &#39;Base Model&#39;<br>});</pre><pre>// Readonly template for display purposes<br>const templateProduct = readonly({<br>  name: &#39;Laptop Template&#39;,<br>  configuration: &#39;Pre-configured&#39;<br>});</pre><pre>function canCustomize(product) {<br>  if (isProxy(product)) {<br>    return `Customization allowed for reactive product: ${product.name}`;<br>  } else {<br>    return `Customization is restricted for non-reactive items: ${product.name}`;<br>  }<br>}</pre><pre>// Example usage<br>console.log(canCustomize(customizableProduct)); // Output: Customization allowed for reactive product: Laptop<br>console.log(canCustomize(templateProduct));    // Output: Customization is restricted for non-reactive items: Laptop Template</pre><h3>2.7 isReactive() and isReadonly()</h3><p>In Vue.js, isReactive() and isReadonly() are two utility functions that allow you to check the reactivity state of an object. These checks are crucial for scenarios where you need to determine whether an object is <strong>reactive</strong> or <strong>readonly</strong>, ensuring proper handling in your application logic.</p><h4>1. isReactive() – Checks if an object is reactive</h4><p>isReactive() checks if an object is a proxy created by reactive() or shallowReactive(). A <strong>reactive</strong> object is one that tracks changes to its properties and updates the view accordingly when those changes occur.</p><h4>2. isReadonly() – Checks if an object is readonly</h4><p>isReadonly() checks if an object is a proxy created by readonly() or shallowReadonly(). A <strong>readonly</strong> object is immutable in terms of direct assignments, meaning its properties cannot be modified directly through the object, although the underlying data might still be mutable.</p><p>Additionally, isReadonly() will return true for computed refs that don&#39;t have a setter function.</p><h3>Real-Life Example: CMS Content Management</h3><p>In a content management system (CMS), you need to distinguish between <strong>live-editable content</strong> (which should be reactive) and <strong>fixed templates</strong> (which should be readonly) to prevent accidental changes to templates while allowing dynamic edits to live content.</p><p>Using isReactive() and isReadonly(), you can create logic that ensures proper handling of these objects.</p><h3>Example Code:</h3><pre>import { reactive, readonly, isReactive, isReadonly } from &#39;vue&#39;;</pre><pre>// Live editable content (reactive)<br>const liveContent = reactive({ text: &#39;Live content&#39; });</pre><pre>// Fixed template (readonly)<br>const template = readonly({ text: &#39;Template content&#39; });</pre><pre>function checkDocumentType(doc) {<br>  if (isReactive(doc)) return &#39;This document is reactive.&#39;;<br>  if (isReadonly(doc)) return &#39;This document is readonly.&#39;;<br>  return &#39;This document is neither reactive nor readonly.&#39;;<br>}</pre><pre>console.log(checkDocumentType(liveContent)); // Output: This document is reactive.<br>console.log(checkDocumentType(template));    // Output: This document is readonly.</pre><h3>3. Conclusion</h3><p>Reactivity utilities in Vue.js are incredibly powerful, but their proper application requires a clear understanding of their roles. Through these detailed real-life examples, you can better visualize</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0e2d0d0d96de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding package.json vs package-lock.json and Why Developers Should Care]]></title>
            <link>https://medium.com/@kanokHossain/understanding-package-json-vs-package-lock-json-and-why-developers-should-care-286b76f7b815?source=rss-3d9138b88ba1------2</link>
            <guid isPermaLink="false">https://medium.com/p/286b76f7b815</guid>
            <category><![CDATA[packagejson]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[package-lock]]></category>
            <category><![CDATA[dependency-management]]></category>
            <category><![CDATA[javascript-development]]></category>
            <dc:creator><![CDATA[Md. Kanok Hossain]]></dc:creator>
            <pubDate>Sun, 29 Dec 2024 16:17:55 GMT</pubDate>
            <atom:updated>2024-12-29T18:18:04.355Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pvapwsXZnououjhQNHNtMA.png" /></figure><p>When managing dependencies in your project, you’ll often see version ranges in the package.json file, such as:</p><ul><li>&quot;express&quot;: &quot;^4.17.1&quot;</li><li>&quot;express&quot;: &quot;~4.17.1&quot;</li></ul><p>But what do these symbols mean? And why is it important to commit package-lock.json? Let’s dive into this!</p><h3>What Do ^ and ~ Mean in Version Ranges?</h3><h4>The ^ (Caret) Symbol:</h4><p>The <strong>caret (</strong><strong>^)</strong> symbol in your package.json allows <strong>updates to minor and patch versions</strong>, but <strong>restricts major version upgrades</strong>. This ensures compatibility and prevents breaking changes in your app.</p><p><strong>Example:</strong></p><ul><li>&quot;express&quot;: &quot;^4.17.1&quot; allows updates to any version <strong>within the </strong><strong>4.x.x range</strong>, such as 4.17.2, 4.18.0, etc.</li><li>However, it <strong>does not allow </strong><strong>5.0.0</strong> because that’s a major version and could introduce breaking changes.</li></ul><h4>The ~ (Tilde) Symbol:</h4><p>The <strong>tilde (</strong><strong>~)</strong> symbol is a bit more restrictive. It only allows <strong>patch updates</strong>, meaning it updates to versions like 4.17.2, but <strong>not </strong><strong>4.18.0</strong>.</p><p><strong>Example:</strong></p><ul><li>&quot;express&quot;: &quot;~4.17.1&quot; allows updates to any version in the 4.17.x range, such as 4.17.2, but not 4.18.0.</li></ul><h3>Scenario 1: The Role of package-lock.json in Your Project</h3><h4>How It Works:</h4><p>When you commit and use package-lock.json, npm will always install <strong>the exact version</strong> of the dependency specified in that file, <strong>even if newer versions are released</strong>.</p><p><strong>Example:</strong></p><ul><li>You specify &quot;express&quot;: &quot;^4.17.1&quot; in package.json.</li><li>When you run npm install, npm installs express@4.17.1, and this version gets locked in package-lock.json.</li><li>If a newer version, like 4.18.0, is released later, <strong>npm won&#39;t install it automatically</strong>.</li><li>If another developer installs dependencies, npm will use package-lock.json to ensure <strong>they get the same version</strong> (4.17.1), regardless of new releases.</li></ul><h4>Benefits:</h4><ul><li><strong>Consistency Across Environments:</strong> Everyone gets the <strong>same version</strong> of dependencies, preventing unexpected behavior.</li><li><strong>Predictability:</strong> Even if a new patch or minor version is released, you continue to work with the version locked in the package-lock.json.</li></ul><h3>Scenario 2: The Impact of Missing package-lock.json in Your Project</h3><h4>How It Works:</h4><p>If you don’t commit package-lock.json, npm will <strong>resolve the latest compatible version</strong> based on the range in package.json.</p><p><strong>Example:</strong></p><ul><li>&quot;express&quot;: &quot;^4.17.1&quot; in package.json will let npm install the <strong>latest compatible version</strong> like 4.17.3 or 4.18.0.</li><li>Without package-lock.json, if a new patch or minor version is released, the next developer who installs dependencies might get that version, leading to slight differences in environments.</li></ul><h4>Potential Issues:</h4><ul><li><strong>Inconsistent Versions:</strong> Developers might end up with <strong>different versions</strong> of the same package, depending on what’s the latest compatible release at the time.</li><li>For example, Developer 1 might get express@4.17.3, while Developer 2 might get express@4.18.0, even though both versions satisfy the range ^4.17.1.</li><li><strong>Breaking Changes with Major Versions:</strong> The good news is, <strong>npm will never install a new major version</strong> (like 5.0.0) if the version range doesn’t allow it. So, if you have &quot;express&quot;: &quot;^4.17.1&quot;, npm won’t install 5.0.0, even without package-lock.json.</li></ul><h3>Why Should You Commit package-lock.json?</h3><ol><li><strong>Ensures Consistency:</strong> By locking your dependencies to specific versions, you ensure that <strong>everyone</strong> in your team or on your deployment platform is using <strong>exactly the same versions</strong> of libraries.</li><li><strong>Avoids Surprises:</strong> Without package-lock.json, you might find that one developer is using express@4.17.2 while another is using 4.18.0. These versions are compatible, but can lead to inconsistencies or bugs that are difficult to debug.</li><li><strong>Predictable Builds:</strong> The package-lock.json file <strong>locks all versions</strong>, even for nested dependencies, so there’s no guessing about what version of a package you’re working with.</li></ol><h3>What Happens If package-lock.json Is Missing?</h3><p>If your project doesn’t have package-lock.json, npm will try to install the latest compatible version of your dependencies based on the version range in package.json.</p><p><strong>Without </strong><strong>package-lock.json:</strong></p><ul><li>If express@4.17.3 is the latest version, it will be installed.</li><li>If 4.18.0 comes out later, that will be installed instead, but <strong>npm will never install </strong><strong>5.0.0</strong> unless the version range in package.json specifically allows it.</li></ul><h3>What Role Does npm update Play?</h3><p>In some cases, you may want to update your dependencies to a newer version. This is where npm update comes into play.</p><h4>How npm update Works:</h4><ul><li>When you run npm update, npm will attempt to update your packages based on the <strong>version range specified in </strong><strong>package.json</strong>.</li><li>For example, if express is currently at 4.17.1 and a new minor version 4.18.0 is available, running npm update will update express to 4.18.0 (since it&#39;s within the ^4.17.1 range).</li></ul><h4>Key Points About npm update:</h4><ul><li><strong>With </strong><strong>package-lock.json</strong>: Running npm update will also update the package-lock.json file to reflect the new versions that are installed, ensuring that everyone else will get the updated versions as well.</li><li><strong>Without </strong><strong>package-lock.json</strong>: Without a package-lock.json, npm update may lead to different versions of packages being installed for different developers, since npm will install the latest compatible version available.</li></ul><h4>When to Use npm update:</h4><ul><li>Use npm update when you want to upgrade your dependencies to the latest versions that <strong>fit within the specified range</strong> in package.json (like moving from 4.17.1 to 4.18.0 if it’s a minor update).</li><li>This command helps keep your project up-to-date without jumping to potentially breaking major versions.</li></ul><h3>The Bottom Line</h3><ul><li><strong>With </strong><strong>package-lock.json:</strong> You get <strong>consistent, predictable versions</strong> across different environments, ensuring no surprises in your dependencies.</li><li><strong>Without </strong><strong>package-lock.json:</strong> npm installs the latest compatible version based on the range in package.json, but it can lead to slight <strong>version mismatches</strong> between different developers or environments.</li></ul><p>So, whether you’re working on a team project or deploying to production, <strong>make sure to commit your </strong><strong>package-lock.json</strong> to avoid inconsistencies and ensure smooth, predictable builds!</p><p>Also, don’t forget that npm update can help keep your dependencies up-to-date without breaking changes—<strong>as long as you commit </strong><strong>package-lock.json</strong>.</p><h3>Key Takeaways:</h3><ul><li>The ^ symbol allows <strong>minor and patch updates</strong>, but <strong>not major version upgrades</strong>.</li><li>The ~ symbol only allows <strong>patch updates</strong>.</li><li>Committing package-lock.json ensures <strong>everyone gets the exact same version</strong> of your dependencies.</li><li><strong>Without </strong><strong>package-lock.json</strong>, there’s a risk of <strong>inconsistent versions</strong> between environments, but you won’t get major version upgrades unless explicitly specified.</li><li><strong>npm update</strong> helps keep your dependencies up-to-date, but always ensure that your package-lock.json is committed for consistency.</li></ul><h3>When Will 5.0.0 Be Installed After 4.17.1?</h3><p>The installation of a <strong>major version</strong> like <strong>5.0.0</strong> depends on how your version range is defined in package.json and whether package-lock.json is used or not. Let’s break it down across different scenarios:</p><h4>Scenario 1: package.json with ^ (Caret) Symbol</h4><p><strong>Example:</strong></p><ul><li>&quot;express&quot;: &quot;^4.17.1&quot;</li></ul><p><strong>How It Works:</strong></p><ul><li>The <strong>caret (</strong><strong>^)</strong> allows <strong>minor and patch version updates</strong>, but <strong>prevents major version updates</strong>.</li><li>This means npm will install the latest compatible minor or patch version (like 4.17.2, 4.18.0, etc.) but will <strong>not install </strong><strong>5.0.0</strong> because it’s a major version.</li></ul><p><strong>Result:</strong></p><ul><li><strong>5.0.0 will NOT be installed</strong> unless you explicitly change the version range to allow major updates (e.g., &quot;express&quot;: &quot;&gt;=4.17.1&quot;).</li></ul><h4>Scenario 2: package.json with ~ (Tilde) Symbol</h4><p><strong>Example:</strong></p><ul><li>&quot;express&quot;: &quot;~4.17.1&quot;</li></ul><p><strong>How It Works:</strong></p><ul><li>The <strong>tilde (</strong><strong>~)</strong> symbol is even more restrictive and only allows <strong>patch updates</strong> within a specific minor version.</li><li>So, npm will install versions like 4.17.2, 4.17.3, etc., but <strong>will not install </strong><strong>4.18.0 or </strong><strong>5.0.0</strong>.</li></ul><p><strong>Result:</strong></p><ul><li><strong>5.0.0 will NEVER be installed</strong> with the tilde symbol (~), as it restricts the update to patch versions only.</li></ul><h4>Scenario 3: package.json with No Tilde (~) or Caret (^) Version Range (e.g., &quot;express&quot;: &quot;4.17.1&quot;)</h4><p><strong>Example:</strong></p><ul><li>&quot;express&quot;: &quot;4.17.1&quot;</li></ul><p><strong>How It Works:</strong></p><ul><li>If you don’t specify a range and just list a version, npm will install that exact version. However, if you later update your version range or modify the version (e.g., &quot;express&quot;: &quot;&gt;=4.17.1&quot;), <strong>it could install </strong><strong>5.0.0</strong> if that’s the latest version that satisfies the new range.</li></ul><p><strong>Result:</strong></p><ul><li>If you change the version range to something like &quot;express&quot;: &quot;&gt;=4.17.1&quot;, <strong>5.0.0 could be installed</strong> as it satisfies the range.</li></ul><h4>Scenario 4: If package-lock.json Exists</h4><p><strong>Example:</strong></p><ul><li>&quot;express&quot;: &quot;^4.17.1&quot;</li><li>package-lock.json is present, locking express@4.17.1.</li></ul><p><strong>How It Works:</strong></p><ul><li>When package-lock.json is committed, <strong>npm will always install the exact version</strong> specified in the lock file, <strong>even if </strong><strong>5.0.0 is released</strong>.</li><li>For example, if express@4.17.1 is locked in the package-lock.json, <strong>running </strong><strong>npm install will always install </strong><strong>4.17.1</strong>, not 5.0.0, even if 5.0.0 is released later.</li></ul><p><strong>Result:</strong></p><ul><li><strong>5.0.0 will NOT be installed</strong> unless you explicitly update the package.json version range or modify the package-lock.json.</li></ul><h4>Scenario 5: If package-lock.json Is Missing</h4><p><strong>Example:</strong></p><ul><li>&quot;express&quot;: &quot;^4.17.1&quot;</li></ul><p><strong>How It Works:</strong></p><ul><li>Without package-lock.json, npm will resolve the latest compatible version based on the range defined in package.json.</li><li>Since the caret (^) symbol allows <strong>minor and patch version updates</strong>, if 4.17.3 or 4.18.0 is released, npm will install that version.</li><li><strong>However, </strong><strong>5.0.0 will NOT be installed</strong>, as npm will avoid major version updates unless explicitly allowed.</li></ul><p><strong>Result:</strong></p><ul><li><strong>5.0.0 will NOT be installed</strong> because the caret symbol restricts the upgrade to a major version. However, if you change the version range to &quot;express&quot;: &quot;&gt;=4.17.1&quot;, 5.0.0 could be installed.</li></ul><h4>Scenario 6: Manual Installation or npm update</h4><p><strong>Example:</strong></p><ul><li>&quot;express&quot;: &quot;^4.17.1&quot; in package.json, with no package-lock.json.</li></ul><p><strong>How It Works:</strong></p><p>If you want to install 5.0.0 manually, you can run:</p><ul><li>npm install express@5.0.0</li></ul><p><strong>Result:</strong></p><ul><li><strong>5.0.0 will be installed</strong> if you manually specify it, and your package.json and package-lock.json will be updated to reflect this new version.</li></ul><h3>Summary</h3><ul><li><strong>With </strong><strong>^ and </strong><strong>~ version ranges</strong> in package.json, npm will never install <strong>major version updates</strong> like 5.0.0 unless you explicitly change the version range in package.json</li><li><strong>If </strong><strong>package-lock.json exists</strong>, npm will <strong>always install the exact version</strong> locked in that file, ensuring consistency.</li><li><strong>Without </strong><strong>package-lock.json</strong>, npm will install the latest compatible version based on your package.json, but <strong>major versions like </strong><strong>5.0.0 won’t be installed automatically</strong> unless you change the version range or manually update it.</li></ul><p><strong>To install </strong><strong>5.0.0</strong>, you can either:</p><ol><li>Manually specify it (e.g., npm install express@5.0.0).</li><li>Change your package.json version range to allow it (e.g., &quot;express&quot;: &quot;&gt;=4.17.1&quot;).</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=286b76f7b815" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring Vue CLI, Vite, and Webpack: Their Connection to Vue.js]]></title>
            <link>https://medium.com/@kanokHossain/exploring-vue-cli-vite-and-webpack-their-connection-to-vue-js-3749b099313e?source=rss-3d9138b88ba1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3749b099313e</guid>
            <category><![CDATA[vue-cli]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[rollup]]></category>
            <category><![CDATA[vitejs]]></category>
            <dc:creator><![CDATA[Md. Kanok Hossain]]></dc:creator>
            <pubDate>Thu, 15 Feb 2024 18:14:30 GMT</pubDate>
            <atom:updated>2024-02-15T18:14:30.010Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bXQ-vg0uYT4M1XV_H0uhKw.jpeg" /></figure><p>In the realm of modern web development, frameworks and build tools play a crucial role in streamlining the development process and enhancing productivity. Vue.js, with its simplicity and flexibility, has gained significant popularity among developers. However, as projects grow in complexity, developers often need to choose the right tools to optimize their workflow. Two popular options for Vue.js projects are Vue CLI and Vite, each offering unique approaches to development. Additionally, understanding how Vue.js relates to Webpack, a powerful module bundler, is essential for grasping the underlying mechanisms of these tools. Let’s dive into these comparisons with practical examples and scenarios.</p><p><strong>Vue CLI:</strong></p><p>Vue CLI, short for Command Line Interface, is the official build tool for Vue.js applications. It provides a full system for rapid Vue.js development, including project scaffolding, dependency management, and configuration. Vue CLI uses Webpack under the hood for module bundling and asset management.</p><p><strong><em>Example Scenario:</em></strong></p><p>Suppose you’re starting a new Vue.js project and want a quick setup with all necessary features like hot module replacement, linting, and testing. Vue CLI comes to the rescue. By running a few commands, you can scaffold a new project with the desired configurations effortlessly.</p><p>For more information and detailed documentation, visit the <a href="https://github.com/vuejs/vue-cli">Vue CLI GitHub repository</a> and the <a href="https://cli.vuejs.org/">official documentation</a>.</p><p><strong>Vite:</strong></p><p>Vite, on the other hand, is a build tool specifically designed for modern JavaScript projects, including Vue.js. Unlike Vue CLI, which relies on Webpack, Vite leverages native browser ES module imports for faster development and hot module replacement. Vite utilizes Rollup for building, and it offers blazing-fast startup and reloading times.</p><p><strong><em>Example Scenario:</em></strong></p><p>Imagine you’re working on optimizing the development experience for an existing Vue.js project. Switching to Vite can significantly improve build times and overall developer productivity, especially in large-scale applications.</p><p>For more information and detailed documentation, visit the <a href="https://github.com/vitejs/vite">Vite GitHub repository </a>and the <a href="https://vitejs.dev/">official documentation</a>.</p><p><strong>Webpack:</strong></p><p>Webpack is a powerful module bundler that helps manage and bundle assets, such as JavaScript files, CSS stylesheets, and images, for web applications. It allows developers to define a dependency graph for their project and generates optimized bundles based on this graph. Webpack is highly configurable and supports various plugins and loaders for tasks like code splitting, minification, and optimization.</p><p><strong><em>Example Scenario:</em></strong></p><p>Consider you’re working on a Vue.js project that requires bundling multiple JavaScript files, CSS stylesheets, and image assets. Webpack can be configured to handle these assets efficiently, optimizing them for production deployment while providing development features like hot module replacement for faster iteration.</p><p>For more information and detailed documentation, visit the <a href="https://github.com/webpack/webpack">Webpack GitHub repository</a> and the <a href="https://webpack.js.org/">official documentation</a>.</p><p><strong>Vue:</strong></p><p>Vue.js is a progressive JavaScript framework that is primarily focused on the view layer of web applications. It provides a simple and intuitive API for building reactive user interfaces. Vue.js can work seamlessly with various build tools and module bundlers like Webpack, Rollup, and Vite.</p><p><strong><em>Example Scenario:</em></strong></p><p>Suppose you’re building a dynamic single-page application (SPA) with Vue.js. You want to handle state management efficiently and utilize features like component-based architecture and reactivity. Vue.js provides all the necessary tools and conventions to accomplish this task seamlessly.</p><p>For more information and detailed documentation, visit the <a href="https://github.com/vuejs">Vue.js GitHub repository</a> and the <a href="https://vuejs.org/">official documentation</a>.</p><p><strong>How Vite, Vue CLI, and Webpack Interact with Vue.js:</strong></p><p><strong><em>Vue CLI and Vue.js:</em></strong> Vue CLI acts as the official command-line interface for Vue.js projects, offering streamlined project setup, dependency management, and configuration. It seamlessly integrates with Vue.js, abstracting away build tool complexities while providing pre-configured setups tailored for Vue.js development.</p><p><strong><em>Webpack and Vue.js:</em> </strong>Webpack, a powerful module bundler, manages project assets and optimizes them for deployment. It integrates seamlessly with Vue.js, leveraging its module bundling capabilities for efficient asset management. Vue CLI, utilizing Webpack under the hood, ensures optimal integration with Vue.js, simplifying the development process.</p><p><strong><em>Vite and Vue.js:</em></strong> Vite represents a modern build tool designed for rapid development, leveraging native browser ES module imports for instant hot module replacement. Although not directly tied to Vue.js, Vite provides first-class support for Vue.js projects, offering unparalleled speed and efficiency during development. Vue CLI’s compatibility with Vite allows developers to choose Vite as an alternative build tool for Vue.js projects, catering to projects prioritizing speed and efficiency.</p><p><strong>Conclusion:</strong></p><p>In summary, understanding the differences between Vite , Vue CLI, and Webpack, is crucial for choosing the right tools for your Vue.js projects. While Vue CLI offers a comprehensive solution with Webpack integration for traditional development workflows, Vite provides a more lightweight and fast alternative using native browser capabilities. Similarly, Vue.js complements Webpack’s powerful bundling capabilities with its focus on building reactive user interfaces. Ultimately, the choice between these tools depends on your project requirements, development preferences, and performance considerations. By leveraging the strengths of each tool, developers can create efficient and maintainable Vue.js applications that meet the demands of modern web development.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3749b099313e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>