Is there a way to adjust the path of a lazily loaded Webpack module?

I have a Vue application that utilizes Webpack and dynamic imports:

// App.vue
<template>
  <div>
    <button @click="isBtnClicked = true">Load lazy component</button>
    <LazyComponent v-if="isBtnClicked" />
  </div>
</template>

<script>
export default {
  name: 'App',
  components: {
    LazyComponent: () => import('./components/LazyComponent'),
  },
  data: () => {
    return {
      isBtnClicked: false,
    }
  }
}
</script>
// components/LazyComponent.vue
<template>
    <p>Hello from lazy component</p>
</template>

Upon clicking the button in the application, the Webpack runtime dynamically generates a <script> tag and attaches it to the head section of the document.

Is there a method to alter the src attribute of this created <script> tag? I aim to include a dynamic query parameter that will be appended to the element in the DOM.

The current generated tag appears as follows:

<script charset="utf-8" src="/js/0.js"></script>

My desired outcome is for it to appear like this:

<script charset="utf-8" src="/js/0.js?mytoken=12345"></script>

where both mytoken and 12345 are produced during runtime.

The technologies I am using include webpack 4.44.0, vue 2.6.11, and vue-loader 15.9.3.

Answer №1

As per the information provided in this source, and also in this discussion, it seems that achieving this functionality in webpack 4 may not be possible. However, there is a possibility that with this proposed update in webpack 5, it could become feasible.

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

Display the full price when no discount is available, but only reveal the discounted price when Vue.js is present

In my collection of objects, each item is structured like this: orders : [ { id: 1, image: require("./assets/imgs/product1.png"), originalPrice: 40, discountPrice: "", buyBtn: require(&q ...

Exploring real-time data updates using React and the setInterval method

Every time my component loads, I am attempting to continuously poll the Spotify API using setInterval. However, during testing, an error message pops up: Invalid Hook Call..etc. I suspect that the issue stems from using useEffect within another useEffect w ...

Having trouble with the API authentication call, receiving a "Failed to load resource: net::ERR_CONNECTION_REFUSED" error message

I am facing an issue with my Vue and .net application. Whenever I run "NPM start serve," it successfully builds the app. The app is running locally at: http://localhost:8080/ However, when I attempt to log in, I encounter the following error: Console err ...

What changes do I need to make in order for this code to be compatible with Google Sites?

I am working on creating a random redirect button and need to modify the code below in two ways: <script> <!-- /* Random redirect button- From JavaScript Kit (http://javascriptkit.com) Hundreds of scripts available for free! Please keep this cred ...

Instead of using a hardcoded value, opt for event.target.name when updating the state in a nested array

When working with a dynamically added nested array in my state, I encounter the challenge of not knowing the key/name of the array. This lack of knowledge makes it difficult to add, update, iterate, or remove items within the array. The problem lies in fun ...

Transform an array from two dimensions to one dimension, while applying specific exceptions

Hello everyone, I'm revisiting a question from before that hasn't been resolved yet. I have a simple requirement - I need a code that will convert my 2D array into a 1D array under one condition. A[0,2,3,7,0,0,5,3][0,2,2,4,0,0,3,0] The desired ...

Mistakes related to using FBXLoader in Three.js

I recently delved into the world of three.js and decided to follow a helpful tutorial on loading GLTF Models using Three.js. Excited to further my skills, I wanted to experiment by utilizing the FBX loader to import and animate models from Mixamo. The tut ...

Encountered an issue while installing npm dependencies for webtorrent: "Error: Unable to locate 'fs' - Fountain-Js (Yeoman)"

Having trouble installing an NPM dependency in my code. Successfully installed the module using this command: npm install --save webtorrent This is the content of my package.json file: ./package.json { "dependencies": { "angular": "^1.5.0" ...

The operation of Ajax can be intermittent, as it may run at

I'm encountering an issue with my ajax code. I am adding data from my database and attempting to refresh a div element. It seems to work sometimes but not consistently. Why is that? Here's the problem - I have a function called addtoqueue. Insid ...

Tips for transferring information between two distinct pages utilizing the jQuery POST technique

I'm dealing with two PHP files called card_process.php and payment.php. My goal is to transfer data from the cart_process page to the payment page. Here's a snippet of the code: In cart_process.php: $paynow = "<button type='submit' ...

I am having trouble getting my AngularJS client to properly consume the RESTful call

As I venture into the world of AngularJS and attempt to work with a RESTful service, I am encountering a challenge. Upon making a REST call to http://localhost:8080/application/webapi/myApp/, I receive the following JSON response: { "content": "Hel ...

Error message 'Invalid Request' encountered when submitting a POST form

When I submit the form in index.html, it is supposed to redirect to results.html to display some information based on the submitted form. However, I am consistently receiving a Bad Request HTTP response and attempting other solutions found on Stack Overflo ...

Issue with rendering Html Element on FireFox compared to Chrome

Having some trouble with an individual component (a simple dropzone) while testing on Firefox. It seems to work fine on Chrome, and the CSS looks good. Css .container { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); wi ...

Encountering an issue with finding the module `scheduler/tracing` in React Native

Encountering an error during the react-native run-android process: Error: Unable to resolve module `scheduler/tracing` from `/Users/miftahali/projects/react/appscustomec/node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js`: Module ...

Is it possible to divide a text string into distinct arrays using spaces?

One method I am familiar with for splitting a string involves using the .split() method, like so: function split(txt) { return txt.split(' '); } When executed, this function would return ['hello', 'world'] if provided wi ...

In PHP, you can customize the colors to emphasize different data sets

In my MySQL database connected through PHP, I have data displayed in table format. My goal is to highlight certain data based on age with two conditions: Condition 1: - Color red (#FF7676) for ages greater than 24 Condition 2: - Color yellow (#F8FF00) fo ...

Need the equivalent syntax of Import in Nodejs

Currently, I have a Node.js application that is still utilizing CommonJS. Everything has been working smoothly so far, but I recently encountered a module that I am not sure how to import. Instead of completely restructuring my application to adhere to the ...

Express.js: Request body with an undefined base64 encoding

I'm currently working on transforming a table in .xls format to individual rows in .csv format. I came across a helpful library for this task called XLSX My initial step involves encoding the .xls table into base64 format. Next, I'm attempting ...

What is the best way to incorporate dynamic elements into a canvas that evolve over time?

Whenever a user interacts with my website by clicking on various parts, I want to display an expanding circle. My idea is to achieve this using a canvas element. Currently, I have successfully implemented the feature where a circle is drawn at the position ...

Gather information from every user and display their user ID in an HTML table, allowing for updates through a button

Can anyone help me create a table like the one shown here: https://i.sstatic.net/Hj4T9.png The table should fetch data from my firebase database. Here is the structure of my requests database: https://i.sstatic.net/0lJGa.png. I've been trying to mo ...