Vitejs is currently loading the entire bundle size instead of just the specific selected files

While working with Vue 3 and Vite, I came across an issue that seems quite strange. The Oh Vue Icons library is loading a massive 108 MB of bundle size, which significantly slows down the loading time even in ViteJS. Here's how my setup looks like:

import { addIcons, OhVueIcon } from 'oh-vue-icons'
import {
  FaFacebookSquare,
  FaInstagram,
  FaLinkedin,
  FaQuora,
  FaTwitter,
  FaYoutube,
} from 'oh-vue-icons/icons'

// register the icons
addIcons(
  FaFacebookSquare,
  FaInstagram,
  FaLinkedin,
  FaQuora,
  FaTwitter,
  FaYoutube
)

const app = createApp(App)
app.component('VIcon', OhVueIcon)
app.mount('#app')

And this is how I'm using these icons in my component:

<VIcon name="fa-facebook-square" />
<VIcon name="fa-youtube" />
<VIcon name="fa-instagram" />
<VIcon name="fa-quora" />
<VIcon name="fa-linkedin" />
<VIcon name="fa-twitter" />

The issue becomes apparent when I try to conditionally display these six icons, resulting in only one or two icons per card.

I am puzzled as to why it's loading such a huge amount of javascript (108 MB). This doesn't seem right at all. Could there be any additional configurations needed for Vite with Vue 3?

Looking forward to your help. Thank you.

Answer №1

According to the Vite documentation:

Enhancing Performance: Vite optimizes ESM dependencies by consolidating many internal modules into a single module, leading to faster page loading times.

Certain packages distribute their ES modules builds as numerous separate files that import each other. For instance, lodash-es comprises more than 600 internal modules! When we execute

import { debounce } from 'lodash-es'
, the browser initiates over 600 HTTP requests concurrently! Despite the server's capability to handle them, the multitude of requests can cause network congestion on the browser end, resulting in slower page loading speeds.

By bundling lodash-es into a single module beforehand, only one HTTP request is necessary!

The oh-vue-icons/icons package consists of numerous files being pre-bundled by Vite during initialization.

If there is no requirement for the icons to be prebundled, you have the option to exclude them using optimizeDeps.exclude:

// vite.config.js
import { defineConfig } from 'vite'

export default defineConfig({
  ⋮
  optimizeDeps: {
    exclude: ['oh-vue-icons/icons']
  }
})

Check out this demo for reference.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Summing up various results from promises [Protractor]

On my webpage, I have set up two input text boxes and a label. My aim is to extract the numbers from these elements, sum up the numbers in the text boxes, and then compare the total with the number in the label. Does anyone know how I can achieve this? He ...

PHP Dropdown List - Default option should be set to "all" (or "Alle")

My website displays data to users based on the State they reside in, with a filter provided through a drop-down list allowing them to select any specific State or view data from all States. Currently, the default selection shows the user data from their ow ...

Jquery not functioning properly for show and hide feature

I'm new to using Jquery and JqueryUI. I have a div named front, which I want to initially display on window load and then hide it by sliding after a delay of 5500 milliseconds. However, I'm encountering errors in the jquery.min.js file. The HTML ...

Can express-handlebars tags be utilized within an HTML script tag when on the client side?

For a while now, I've been facing a challenge. I'm in the process of building an application with express-handlebars and so far everything is going smoothly. The data that needs to be displayed on the webpages looks good thanks to the Helper func ...

Is there a way for me to discover the identity of the victor?

There are 4 divs that move at different, random speeds each time. I am trying to determine which one is the fastest or reaches the goal first. Additionally, there is a betting box where you can choose a horse to bet on. I need to compare the winner with my ...

The request body is not defined within the Express controller

Currently facing an issue with my controller: when I use console.log(req), I can see all the content of the request body. However, when I try console.log(req.body), it returns as undefined. This problem arises while working on my Portfolio project with Nex ...

Angular.js and D3 - The Perfect Combination for Dynamic Data Visualization!

Having some trouble creating a chart with angular.js. The chart is not appearing on the page when using rout.js, but it works fine without it. Here's my code: var myapp = angular.module('myapp', ['angularCharts']); function D3 ...

What is the best way to iterate through anchor links surrounding an image and dynamically load content into the figcaption element using AJAX?

Seeking assistance for an issue related to my understanding of the $this keyword in jQuery. I am facing a problem where I have 3 images on a page, each wrapped in an anchor link. My goal is to loop through these links, retrieve the URL of each anchor lin ...

What aspects of MongoDB security am I overlooking?

Is it a secure way to connect to Mongo DB by using Node JS, Mongo DB, and Express? Could someone provide an explanation of this code in terms of security? === Many tutorials often only show... var mongoClient = new MongoClient(new Server('localhos ...

Counting JSON Models in SAP UI5

I am encountering a particular issue. Please forgive my imperfect English. My goal is to read a JSON file and count the number of persons listed within it. I want this result to be stored in a variable that is linked to the TileContainer. This way, whenev ...

Securely getting a data point from a pathway

Within my Angular project, I recently made the transition from using query string elements in URLs such as: http://www.whatever.com/products?productName=TheMainProduct&id=234234 To a route-based system like this: http://www.whatever.com/products/The ...

What is the best way to tailor my functions to apply only to specific objects within an array, instead of affecting them all?

I am facing an issue where my functions showMore and showLess are triggering for all objects in the array when onClick is fired. I want these functions to be called individually for each object. Both of these functions are responsible for toggling betwee ...

Achieve a smooth sliding effect for a div element in Vue using transition

When utilizing transitions in conjunction with v-if, it appears that the div is initially created and then the animation occurs within that div. Is there a way to have the div move along with the text during the animation? For example, when clicking on th ...

Changing webpage content without using asynchronous methods once authentication has been completed using Google Firebase

My goal is to create a website where users can sign in with Google by clicking a button, and then be redirected to a new HTML page. However, I am facing an issue where the Google sign-in window pops up briefly and closes immediately, causing the HTML page ...

Tips for utilizing boolean values in form appending with Vue.js

I am currently attempting to send availability as a boolean value. However, despite my efforts, it keeps sending false to my database. Here is my code snippet: <input v-model="availability" /> </d ...

What could be causing the preloader to fail in my React application?

I am developing a React App with Redux functionality, and I am looking to implement a preloader when the user clicks on the "LoginIn" button. To achieve this, I have created a thunk function as follows: export const loginInWithEmail = (email, password) =&g ...

Having issues with an Android app crashing on Android 12+ devices when receiving push notifications in the background. This problem is occurring with an

An error occurred with the Firebase-FCMService while running the app. The specific process and PID are as follows: com.petbacker.android, 4405. This issue is related to an IllegalArgumentException stating that targeting S+ (version 31 and above) requires e ...

Learn how to render list items individually in Vue.js using the 'track-by $index' directive

Recently, I switched from using v-show to display elements in an array one at a time in my Vue instance. In my HTML, I had this line: <li v-for="tweet in tweets" v-show="showing == $index">{{{ tweet }}}</li>". The root Vue instance was set up l ...

javascript utilizing underscorejs to categorize and aggregate information

Here is the data I have: var dates = [ {date: "2000-01-01", total: 120}, {date: "2000-10-10", total: 100}, {date: "2010-02-08", total: 100}, {date: "2010-02-09", total: 300} ]; My goal is to group and sum the totals by year like this. ...

Unlock the navigation tab content and smoothly glide through it in Bootstrap 4

Hey there, I have managed to create two functions that work as intended. While I have some understanding of programming, I lack a background in JavaScript or jQuery. The first function opens a specific tab in the navigation: <script> function homeTa ...