Build your Vue.js application using modules

We have a project consisting of approximately 100 pages that we are in the process of migrating to a newer front-end technology. We have almost decided on using Vue.js (with Vue CLI) for this migration. However, we are facing an issue with Vue CLI building the entire project into one build.js file. Due to our frequent requirement changes, this means that every small change requires us to upload the entire build.js file, leading to the need for regression testing of the entire project. Is there a way to build the project module-wise so that only the changed module needs to be uploaded live after making changes?

Answer №1

Implementing Lazy Loading with Vue Router:

This method instructs the compiler (Webpack) to "return" the component instead of "including" it, resulting in the component being isolated into its own file for lazy loading purposes.

For example:

export default new Router({
    routes: [
        // Home component to be included in bundle.js
        {
            path: '/',
            name: 'home',
            component: Home
        },
        // Code splitting - generate a separate unique chunk for the about component.
        {
            path: '/about',
            name: 'about',
            component: () => import(/* webpackMode: "lazy" */ '@/views/About.vue')
        }
    ]
})

Output = bundle.js and about.js or any number of files depending on the components per page.


Customizing Webpack Configuration in Vue:

You can customize and adjust the default compiler (Webpack) configuration by adding a vue.config.js file to the root of your project.

For instance:

// vue.config.js
module.exports = {
  configureWebpack: config => {
    if (process.env.NODE_ENV === 'production') {
      // Mutate config for production...
    } else {
      // Mutate for development...
    }
  }
}

It's important to thoroughly review the documentation at https://cli.vuejs.org/guide/webpack.html to ensure that certain settings are not directly altered.

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

What advantages does mapState offer compared to mapGetters when working with Vuex?

While evaluating the company code, I came across a Vue component with computed properties structured like this: computed: { ...mapState('settings', { site: state => state.general.site }), ...mapGetters('settings', ...

Develop a dynamic modal feature that allows users to input SQL queries and execute them seamlessly without having to

I need to implement a feature in my web application where users can set the price of an item displayed in an HTML table that is populated from a MySQL database. When a user clicks on a button next to a row, a modal should open with a text input field and a ...

Using JSON parsing to dynamically create classes with preloaded background images

Today, I successfully deployed my browser game using MVC4 to my website for the first time. I am currently navigating through the differences between running the site off of localhost and running it from the actual website. My process involves loading all ...

Using Javascript to save basic high scores to a server

My JS game involves updating a score variable. When the game reaches a gameOver state, I want to compare the score to one saved on the server. If the player got a higher score, I'd like to overwrite the previous high score with the new one. If it&apos ...

Exploring the World of Browserify Submodules

/xyz /abc.js /abcdef.js /index.js When working with node.js, if you use the require statement for a directory (require('xyz')), it will automatically search for an index.js file within that directory and return the exports defined in that ...

Increase the count if the item is already in the shopping cart - React

Is there a way to avoid adding the same product to the basket multiple times and instead just increment a counter? How can I effectively keep track of each item's count? this.state = { description: '', commaSalesPrice: '', ...

What is the correct way to include a variable such as /variable/ in a MongoDB query?

I need help passing in a searchTerm from a variable, what is the best way to do this? const mongoquery = { description: { $in: [ /searchTerm/ ] } }; I attempted it like this initially: const mongoquery = { description: { $in: [ `/${searchTerm}/` ] } }; H ...

Tips for securing a navbar in material ui

https://i.stack.imgur.com/CYfmQ.png In my current React project, I am facing an issue with aligning components within the Material-UI AppBar Component. My aim is to achieve a seamless and perfectly straight alignment for three key elements: a logo image, ...

Unexpected behavior of ion-select: No rendering of selected value when applied to filtered data

I came across an unexpected issue with the dynamic data filtering feature of ion-select. In my application, users are required to choose three unique security questions during registration. I have an array of available questions: questions: Array<{isSe ...

Form validation is an essential feature of the Angular2 template-driven sub form component

I'm currently working on a template-driven form that includes a group of inputs generated through an ngFor. My goal is to separate this repeating 'sub-group' into its own child component. However, I'm encountering difficulties in ensur ...

Stop listening to Firestore updates upon logging out

One approach to accomplish this task is detailed here Yet, I'm encountering difficulties in triggering the unsubscribe function within an onAuthStateChanged method located in a separate Vuex module. In the user.js store: ... onAuthStateChanged({ ...

Sharing Laravel routes with vue components

In my `index.blade.php`, I have incorporated Vue code into the view. Generally, we pass Laravel routes like this: <a href="{{route('some-route')}}"> Link </a> Now, picture a scenario where I have a main Vue component within this `in ...

Having trouble retrieving features from a QR code generated with Angularx-qrcode?

I utilized angularx-qrcode in order to create a QR code that displays data from qrInfo. However, I'm encountering the following error: ERROR TypeError: Cannot read properties of undefined (reading 'qrcElement') The code within qr-code-gener ...

jQuery-powered web application, experiencing compatibility issues when deployed on Windows Server 2003 and Internet Explorer

While developing a web application on XP and FF (with occasional IE checks through IE 8), I encountered an issue when deploying it to a WS 2003 site running IE 7. My jQuery code for dynamically sizing divs does not execute, even when explicitly stating div ...

The function document.getElementById is unable to select multiple elements simultaneously

I've been tackling a loading issue. I have a visible div, #loading, and multiple hidden divs, #message. I also have a JavaScript function. function loading() { setTimeout(function() { document.getElementById("loading").style.display = " ...

HTTP GET request not updating data

I'm experimenting with AngularJS and trying out some examples: Here's the HTML code snippet: <html ng-app="myApp"> <body ng-controller="JokesController"> <h1>{{ joke }}<h1> </body> </html> A ...

Why isn't my SCO considered complete?

My SCO is very basic, with an empty html page. I am utilizing the pipwerks scorm api wrapper in Chrome dev tools to establish a connection to the LMS, set cmi.completion_status to "completed", and cmi.success_status to "failed" (as outlined in the scorm ru ...

Displaying an 'undefined' message in a JavaScript alert box

Hello! Just made the switch from C#/C++ to JavaScript recently and I'm really enjoying it. I've encountered a behavior that has me scratching my head, can anyone help explain? So here's what's happening: when I run this script, I see ...

What is the best way to extract the ID of an element that triggers an OnChange event?

Just a heads up: The solution to my problem ended up being CSS code that was triggered by clicking on a widget. Once I realized it was CSS, along with the widget name and hover action, I was able to handle it successfully. Previous question before the PS ...

If the user confirms it with a bootstrap dialog box, they will be redirected to the corresponding links

Firstly, I am not interested in using javascript confirm for this purpose. Please read on. For example, adding an onClick attribute to each link with a function that triggers a system dialog box is not what I want. Instead of the standard system dialog bo ...