Form Input Checkbox Resets API Response Value When Unchecked?

So I have this app that you select a checkbox & tip and it will show the total amount and add/subtract when you unselect/select other options.

Here is a codepen of the basic app not including the API function
https://codepen.io/jaysomo10/pen/mdXoRWz

So you can see from the codepen, the basic checkboxes and tips work completely fine.

I am connected to an API and after I add my delivery address, it will calculate the delivery fee and add it to my total value.

My problem is that once I calculate the delivery fee, then I select a checkbox option, and then I unselect that option, it will reset the total value and now my total value doesn’t show the delivery fee included.

Example: I select $10 menu option and then $5 tip so my total is now $15. Then, I go and calculate my delivery fee and it will show $7 delivery fee + the $15 food total which equals $22 for everything. The problem is if I unselect the $10 food item, it will reset the order total from $22 back to the tip value of $5 but my delivery fee is still showing in the HTML as $7 yet the order value total isn’t including the delivery fee in the total.

Here is my JS function for the delivery fee. Note this code works completely fine as long as I only select checkboxes and never unselect any. The moment I unselect a checkbox is when the values reset and the order total becomes wrong because it no longer includes the delivery fee.

async function getFee() {
  const payload = getFormValues();
  const finalPayload = JSON.stringify(payload);

  const formInput = document.querySelector("form");
  console.log(formInput);

  if (formInput.checkValidity()) {
    console.log("YES");

    const response = await fetch("/get-fee", {
      method: "POST",
      body: finalPayload,
      headers: { "Content-Type": "application/json" },
    })
      .then(async (response) => {
        const resp = await response.json();
        return resp;
      })
      .catch((rejected) => {
        console.log(rejected);
      });

    const deliveryField = document.getElementById("fee");
    const orderTotal = document.getElementById("total");
    tipVal = document.querySelector(".tips:checked").value;
    window.tips = tipVal;

    foodTotal.textContent = `$${(window.menuItems / 100).toFixed(2)}`;
    tipTotal.textContent = `$${(window.tips / 100).toFixed(2)}`;
    deliveryField.innerHTML = `$${(response.fee / 100).toFixed(2)}`;
    orderTotal.textContent = `$${(
      (Number(window.menuItems) + Number(window.tips) + response.fee) /
      100
    ).toFixed(2)}`;
  } else {
    console.log("You need to fill out the form");
  }

}

My issue is I don’t know how to get the response.fee value into my other JS file that allows me to add/subtract the checkbox values and tips.

Basically, the JS file in my codepen doesn’t know the delivery fee until after I submit an address, hence the logic for the code simply adds/subtracts the values and it can’t include the delivery fee in the total because it doesn’t know what it is until I submit that info

Javascript closures in generat ID

var generateID=function() {
    var prefix="uid-";
    var count=0;

    return function(){
        count+=1;
        console.log(prefix+count)
    }
}
var create = generateID();

console.log(create());
console.log(create());
console.log(create());

Expected output:
uid-1
uid-2
uid-3

Help me in undefined error part in output.

How to keep pushing new values from a dataset on click event to an array

Trying to add the dice roll value from a data set every time the roll dice click is triggered and a new number is produced from a random math function.

Currently, the value is added to the array but only one value is added and the array is not incremented with each new roll value.

What is the best approach to push each new value to the array? Including a maximum of 25 additions.

The goal is to first console log each dice roll value and then eventually display them in the html as a list of 25 roll results.

Code Below:

function rollDice() {
    const dice = [...document.querySelectorAll(".die-list")];
    dice.forEach(die => {
      toggleClasses(die);
      die.dataset.roll = getRandomNumber(1, 6);
      let res1 = document.getElementById("die-1").dataset.roll;
      let res2 = document.getElementById("die-2").dataset.roll;
      let res1Num = parseInt(res1);
    
      let resConten1 = document.getElementById("result1");
      let resConten2 = document.getElementById("result2");
      resConten1.innerHTML = res1;
      resConten2.innerHTML = res2;
      
      // Results Array 
      let res1Arr = [];
      console.log(res1Arr);
  
       if (res1Num < 25 ) {      
        res1Arr.push(res1Num);
        console.log(res1Arr);
        } 
  
    });
  
  }
  

  
    
  
  function toggleClasses(die) {
    die.classList.toggle("odd-roll");
    die.classList.toggle("even-roll");
  }
  
  function getRandomNumber(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min + 1)) + min;
  }
  
  
  document.getElementById("roll-button").addEventListener("click", rollDice);
  
  
* {
  margin: 0;
  padding: 0;
  vertical-align: baseline;
}
html {
  font-family: system-ui, sans-serif;
}
body {
  background: linear-gradient(#545454, #454545, #676767);
  display: grid;
  grid-template-columns: 1fr;
  height: 100vh;
  overflow: hidden;
  width: 100%;
}
.dice {
  align-items: center;
  display: grid;
  grid-gap: 2rem;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  grid-template-rows: auto;
  justify-items: center;
  padding: 2rem;
  perspective: 600px;
}
.die-list {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  height: 6rem;
  list-style-type: none;
  transform-style: preserve-3d;
  width: 6rem;
}
.even-roll {
  transition: transform 1.5s ease-out;
}
.odd-roll {
  transition: transform 1.25s ease-out;
}
.die-item {
  box-shadow: inset -0.35rem 0.35rem 0.75rem rgba(143, 142, 142, 0.3),
    inset 0.5rem -0.25rem 0.5rem rgba(176, 175, 175, 0.15);
  display: grid;
  grid-column: 1;
  grid-row: 1;
  grid-template-areas:
    "one two three"
    "four five six"
    "seven eight nine";
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  height: 100%;
  padding: 1rem;
  width: 100%;
}

.die-item2 {
  box-shadow: inset -0.35rem 0.35rem 0.75rem rgba(0, 0, 0, 0.3),
    inset 0.5rem -0.25rem 0.5rem rgba(0, 0, 0, 0.15);
  display: grid;
  grid-column: 1;
  grid-row: 1;
  grid-template-areas:
    "one two three"
    "four five six"
    "seven eight nine";
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  height: 100%;
  padding: 1rem;
  width: 100%;
}


.dot {
  align-self: center;
  background-color: white;
  border-radius: 50%;
  box-shadow: inset -0.15rem 0.15rem 0.25rem rgba(0, 0, 0, 0.5);
  display: block;
  height: 1.25rem;
  justify-self: center;
  width: 1.25rem;
}





/* Dice Colors */

.die-item[data-side="6"] {
  background-color: black;
}
.die-item[data-side="5"] {
  background-color: black;
}
.die-item[data-side="4"] {
  background-color: black;
}
.die-item[data-side="3"] {
  background-color: black;
}
.die-item[data-side="2"] {
  background-color: black;
}
.die-item[data-side="1"] {
  background-color: black;
}

/* Dice Colors 2  */

.die-item2[data-side="6"] {
  background-color: red;
}
.die-item2[data-side="5"] {
  background-color: red;
}
.die-item2[data-side="4"] {
  background-color: red;
}
.die-item2[data-side="3"] {
  background-color: red;
}
.die-item2[data-side="2"] {
  background-color: red;
}
.die-item2[data-side="1"] {
  background-color: red;
}


.even-roll[data-roll="1"] {
  transform: rotateX(360deg) rotateY(720deg) rotateZ(360deg);
}
.even-roll[data-roll="2"] {
  transform: rotateX(450deg) rotateY(720deg) rotateZ(360deg);
}
.even-roll[data-roll="3"] {
  transform: rotateX(360deg) rotateY(630deg) rotateZ(360deg);
}
.even-roll[data-roll="4"] {
  transform: rotateX(360deg) rotateY(810deg) rotateZ(360deg);
}
.even-roll[data-roll="5"] {
  transform: rotateX(270deg) rotateY(720deg) rotateZ(360deg);
}
.even-roll[data-roll="6"] {
  transform: rotateX(360deg) rotateY(900deg) rotateZ(360deg);
}
.odd-roll[data-roll="1"] {
  transform: rotateX(-360deg) rotateY(-720deg) rotateZ(-360deg);
}
.odd-roll[data-roll="2"] {
  transform: rotateX(-270deg) rotateY(-720deg) rotateZ(-360deg);
}
.odd-roll[data-roll="3"] {
  transform: rotateX(-360deg) rotateY(-810deg) rotateZ(-360deg);
}
.odd-roll[data-roll="4"] {
  transform: rotateX(-360deg) rotateY(-630deg) rotateZ(-360deg);
}
.odd-roll[data-roll="5"] {
  transform: rotateX(-450deg) rotateY(-720deg) rotateZ(-360deg);
}
.odd-roll[data-roll="6"] {
  transform: rotateX(-360deg) rotateY(-900deg) rotateZ(-360deg);
}
[data-side="1"] {
  transform: rotate3d(0, 0, 0, 90deg) translateZ(4rem);
}
[data-side="2"] {
  transform: rotate3d(-1, 0, 0, 90deg) translateZ(4rem);
}
[data-side="3"] {
  transform: rotate3d(0, 1, 0, 90deg) translateZ(4rem);
}
[data-side="4"] {
  transform: rotate3d(0, -1, 0, 90deg) translateZ(4rem);
}
[data-side="5"] {
  transform: rotate3d(1, 0, 0, 90deg) translateZ(4rem);
}
[data-side="6"] {
  transform: rotate3d(1, 0, 0, 180deg) translateZ(4rem);
}
[data-side="1"] .dot:nth-of-type(1) {
  grid-area: five;
}
[data-side="2"] .dot:nth-of-type(1) {
  grid-area: one;
}
[data-side="2"] .dot:nth-of-type(2) {
  grid-area: nine;
}
[data-side="3"] .dot:nth-of-type(1) {
  grid-area: one;
}
[data-side="3"] .dot:nth-of-type(2) {
  grid-area: five;
}
[data-side="3"] .dot:nth-of-type(3) {
  grid-area: nine;
}
[data-side="4"] .dot:nth-of-type(1) {
  grid-area: one;
}
[data-side="4"] .dot:nth-of-type(2) {
  grid-area: three;
}
[data-side="4"] .dot:nth-of-type(3) {
  grid-area: seven;
}
[data-side="4"] .dot:nth-of-type(4) {
  grid-area: nine;
}
[data-side="5"] .dot:nth-of-type(1) {
  grid-area: one;
}
[data-side="5"] .dot:nth-of-type(2) {
  grid-area: three;
}
[data-side="5"] .dot:nth-of-type(3) {
  grid-area: five;
}
[data-side="5"] .dot:nth-of-type(4) {
  grid-area: seven;
}
[data-side="5"] .dot:nth-of-type(5) {
  grid-area: nine;
}
[data-side="6"] .dot:nth-of-type(1) {
  grid-area: one;
}
[data-side="6"] .dot:nth-of-type(2) {
  grid-area: three;
}
[data-side="6"] .dot:nth-of-type(3) {
  grid-area: four;
}
[data-side="6"] .dot:nth-of-type(4) {
  grid-area: six;
}
[data-side="6"] .dot:nth-of-type(5) {
  grid-area: seven;
}
[data-side="6"] .dot:nth-of-type(6) {
  grid-area: nine;
}

.result-table {
  background-color: white;
  text-decoration-color: black;
  font-size: 1.25rem;
  font-weight: 700;
  justify-self: center;
  padding: 0.5rem 1rem;
}

.result1::after {
  text-decoration: blue;
  content: attr(data-roll);
}

#result2 {
  text-decoration: yellow;
}


button {
  align-self: center;
  background-color: #efefef;
  border: none;
  color: #333;
  font-size: 1.25rem;
  font-weight: 700;
  justify-self: center;
  padding: 0.5rem 1rem;
}
button:hover {
  cursor: pointer;
}

@media (min-width: 900px) {
  .dice {
    perspective: 1300px;
  }
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Dice Game</title>
    <link rel="stylesheet" href="./styles.css" />
  </head>
  <body>
    <div class="dice">
      <ol class="die-list even-roll" data-roll="1" id="die-1">
        <li class="die-item" data-side="1">
          <span class="dot"></span>
        </li>
        <li class="die-item" data-side="2">
          <span class="dot"></span>
          <span class="dot"></span>
        </li>
        <li class="die-item" data-side="3">
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
        </li>
        <li class="die-item" data-side="4">
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
        </li>
        <li class="die-item" data-side="5">
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
        </li>
        <li class="die-item" data-side="6">
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
        </li>
      </ol>
      <ol class="die-list odd-roll" data-roll="1" id="die-2">
        <li class="die-item2" data-side="1">
          <span class="dot"></span>
        </li>
        <li class="die-item2" data-side="2">
          <span class="dot"></span>
          <span class="dot"></span>
        </li>
        <li class="die-item2" data-side="3">
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
        </li>
        <li class="die-item2" data-side="4">
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
        </li>
        <li class="die-item2" data-side="5">
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
        </li>
        <li class="die-item2" data-side="6">
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
          <span class="dot"></span>
        </li>
      </ol>
    </div>
    <button type="button" id="roll-button">Roll Dice</button>
    <div class="result-table">
      <h2>Results</h2>
        <div id="result1" > </div>
        <div id="result2"></div>
    </div>
    <script src="./app.js"></script>
  </body>
</html>


<!-- <ol class="die-list odd-roll" data-roll="1" id="die-2">
  <li class="die-item" data-side="1">
    <span class="dot"></span>
  </li>
  <li class="die-item" data-side="2">
    <span class="dot"></span>
    <span class="dot"></span>
  </li>
  <li class="die-item" data-side="3">
    <span class="dot"></span>
    <span class="dot"></span>
    <span class="dot"></span>
  </li>
  <li class="die-item" data-side="4">
    <span class="dot"></span>
    <span class="dot"></span>
    <span class="dot"></span>
    <span class="dot"></span>
  </li>
  <li class="die-item" data-side="5">
    <span class="dot"></span>
    <span class="dot"></span>
    <span class="dot"></span>
    <span class="dot"></span>
    <span class="dot"></span>
  </li>
  <li class="die-item" data-side="6">
    <span class="dot"></span>
    <span class="dot"></span>
    <span class="dot"></span>
    <span class="dot"></span>
    <span class="dot"></span>
    <span class="dot"></span>
  </li>
</ol> -->

How to get the window selection for nested nodes have shadow DOM

If we have nested elements with shadow DOM and try to get selection using. Is there any way to get the correct one for any selection includes cases like this?

window.getSelection() // incorrect selection
window.getSelection().getRangeAt(0).getClientRects() // DOMRectList {length: 0}

enter image description here

const main = document.querySelector('main');
const arr = "Lorem ipsum dolor sit, amet consectetur adipisicing elit. Laudantium, eaque!".split(' ');
for (let i = 0; i < arr.length; i++) {
  const div = document.createElement('span');
  const shadowRoot = div.attachShadow({
    mode: 'open'
  });
  shadowRoot.appendChild(document.createTextNode(arr[i] + " "));
  main.appendChild(div);
}

const spans = [...document.querySelectorAll('.span-has-shadow')];
for (let i = 0; i < spans.length; i++) {
  const span = spans[i];
  const text = span.dataset.text;
  const root = span.attachShadow({
    mode: 'open'
  });
  root.appendChild(document.createTextNode(text + " "));
  if (i > 0) {
    const prev = spans[i - 1];
    prev.shadowRoot.appendChild(span);
  }
}
main>* {
  font-size: 1.5em;
  font-family: cursive;
}

main {
  margin: auto;
  width: 1000px;
}

#shadow-root {
  color: blue;
  margin-top: 1em;
}

h2 {
  text-align: center;
}
  <main></main>

  <h2>
    <span class="span-has-shadow" data-text="lorem">
      <span class="span-has-shadow" data-text="ipsum">
        <span class="span-has-shadow" data-text="dolor">
          <span class="span-has-shadow" data-text="sit">
            <span class="span-has-shadow" data-text="amet">
              <span class="span-has-shadow" data-text="consectetur">
                <span class="span-has-shadow" data-text="adipiscing">
                  <span class="span-has-shadow" data-text="elit">
                  </span>
                </span>
              </span>
            </span>
          </span>
        </span>
      </span>
    </span>
  </h2>

  <script>
  
  </script>

How to make a pdf from MongoBD Binary with File API?

I would like some help to make a File object from a pdf stored in MongoDB.
I am not using GridFS, the file is stored as such:
File structure in MongoDB

I am using this function to make the File:
handlegetfile function

The .pdf file created by the writeFile() function can’t be opened, and when opened with an editor, it looks like this:
pdf data after retrieved

Important: I do not want to write the file to the disk, writeFile() is just here to be sure that the pdf can be opened.

The thing is: the data goes from this in the original file:
original pdf data

To this in MongoDB:
data in MongoDB

To what is in the third screenshot. I am pretty sure the problem comes from the cast to a Uint8array but I can’t find what else to use there for it to work. I tried exploding the response with {...result.data.File} and using an ArrayBuffer, but I couldn’t get it to work either way.

Could you help me please ?

Ant design Tree in React not updating

I’m using a state management to handle websocket updates. If I render the values everything is fine, but when I’m using the Antd Tree component, it always shows the previous state.

const serviceTreeData = useServiceTreeStore((store) => store.serviceTreeData);
const [treeData, setTreeData] = React.useState(serviceTreeData);
 React.useEffect(() => {
    const data = serviceTreeData.map(data => cloneDeep(data))
    setTreeData(data);
}, [serviceTreeData]);

I tried to deep copy in case if that’s the problem, but it didn’t help.

How can I reconstruct raw headers from request into an array?

I am trying to reconstruct the raw headers from the request object from looking like this:

[{"0": "Host"},
 {"1": "localhost:3000"},
 {"2": "Connection"},
 {"3": "keep-alive"}, 
{"4": "sec-ch-ua"}, 
{"5": "" Not A;Brand";v="99", "Chromium";v="102", "Google Chrome";v="102""}]

to something like:

[{ "Host: "localhost:3000"}, {"Connection": "Keep alive"}]

is this possible in javascript?

Webpack have just one html import, without having to implicitly import other chunks

I have multiple entrypoints in my project which have different chunks (for example a vendor chunk). Now the issue is that my entrypoints don’t work without implicitly importing the vendor chunk and the runtime file.

What I have to do

<script defer="defer" src="runtime.js"></script>
<script defer="defer" src="399.js"></script>
<script defer="defer" src="standalone.js"></script>

What I want to do

<script defer="defer" src="standalone.js"></script>

How can I make it so by just importing standalone.js it automatically imports runtime.js and 399.js without having to implicitly do this in the html file. Can this be done?

Config

module.exports = {
    entry: {
        standalone: path.resolve(__dirname, '../src/index.standalone.tsx')
    },
    resolve: {
        extensions: ['.tsx', '.ts', '.js']
    },
    output: {
        path: path.resolve(__dirname, '..', './build')
    },
    optimization: {
        runtimeChunk: 'single',
        splitChunks: {
            chunks: 'all'
        }
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: path.resolve(__dirname, '..', './public/index.standalone.html')
        })
    ]
};

Is there a command to solve this problem? [duplicate]

I am in this directory

C:UsersmaxDesktopgappizza

when I write this command it shows me an strange error.

command :

npm run dev

errors :

{
npm WARN config global --global, --local are deprecated. Use --location=global instead.
npm ERR! Missing script: “dev”
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run

npm ERR! A complete log of this run can be found in:
npm ERR! C:UsersmaxAppDataLocalnpm-cache_logs2022-06-16T08_44_13_517Z-debug-0.log
}

also it’s package.json :

{
"name": "pizza",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "12.1.6",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"eslint": "8.17.0",
"eslint-config-next": "12.1.6"
}
}

could you help me pleaase ?

Javascript– I have a from where you register new user and after registering you can choose which user you wanna select, how to make after

Javascript– I have a from where you register new user and after registering you can choose which user you wanna select, how to make after registering the user, you can directly selecting the new user ( i mean after registering to show on the list firstly new user )

  // this.selectedCustomer = customer;           // does not work here... 

TinyMCE inline mode with iframe

In short, I would like to ask, if it would be possible to initialize TinyMCE inside dynamicly created iframe. It looks like TinyMCE was initialized, but the events not working

I’m trying to add TinyMCE with inline mode on my site. I have to use inline mode because only this mode supports fixed_toolbar_container. The toolbar has to be placed on top of page. TinyMCE will be used to edit content in back office and then content will be displayed for regular users. I have to load custom CSS into TinyMCE to have for example proper color for header, but I don’t want those styles to affect the back office.
I tried to create a dynamic iframe in back office create a content a toolbars containers inside, but it looks like something is wrong, for example I can’t select text and use Bold style.

I have code example: https://codepen.io/gregwi/pen/bGLZpvx

In the code above:

  1. Creating a sanbox iframe element (other iframes modes didn’t work too for me)
  2. Add container and toolbar containers to iframe
  3. Define configuration for tinyMCE. Configuration use elements from iframe as configuration for TinyMCE
  4. Initialize the TinyMCE

Dynimically add step to linear gradient of an svg with javascript

I’m trying to add some step to a linear gradient tag inside an svg with js.

My code works, meaning the markup is correct after the script run, but the svg is not updated/re-rendered.

I start with something like this

<svg
      id="animatedPath"
      width="552"
      height="61"
      viewBox="0 0 552 61"
      fill="none"
      xmlns="http://www.w3.org/2000/svg"
    >
      <path
        id="pathToAnimate"
        d="M-22.125 45.875C42.5625 54.3125 56.625 31.8119 98.8125 20.5625C129.589 12.3558 166.31 9.3125 183.188 17.7506C205.688 29 218.018 54.3125 239.438 54.3125C261.938 54.3125 284.438 34.625 312.562 20.5625C340.688 6.5 345.75 9.3125 377.25 9.3125C416.625 9.3125 470.062 45.875 489.75 54.3125C509.438 62.75 524.639 55.9499 529.125 40.25C534.75 20.5625 534.75 6.5 616.312 3.6875"
        stroke-width="5.625"
        stroke-linecap="round"
      />
      <defs>
        <linearGradient
          id="logoGradient"
          x1="3.18749"
          y1="14.9375"
          x2="548.812"
          y2="20.5625"
          gradientUnits="userSpaceOnUse"
        ></linearGradient>
      </defs>
    </svg>

and in my js code i do a simple loop on a color array

let linearGradient = document.querySelector(
  "#animatedPath defs linearGradient"
);

let gradient=["#FFE600", "#05FF00", "#00D1FF", "#FF0000"];

gradient.forEach((color, index) => {
  let stop = document.createElement("stop");
  stop.setAttribute("offset", index / 4);
  stop.setAttribute("stop-color", color);
  linearGradient.appendChild(stop);
});

The code works, i can see the step inside the linear gradient but the svg is not updated.
If i put the step manually in the svg it clearly works, and if later in the code i try to manipulate the steps whit js, the svg get updated.

I’ve read some stuff about suspendRedraw, but also that is deprecated and may not apply to this case.

Does anybody has any suggestion?

let linearGradient = document.querySelector(
  "#animatedPath defs linearGradient"
);

let gradient = ["#FFE600", "#05FF00", "#00D1FF", "#FF0000"]

gradient.forEach((color, index) => {
  let stop = document.createElement("stop");
  stop.setAttribute("offset", index / 4);
  stop.setAttribute("stop-color", color);
  linearGradient.appendChild(stop);
});
 <svg
      id="animatedPath"
      width="552"
      height="61"
      viewBox="0 0 552 61"
      fill="none"
      xmlns="http://www.w3.org/2000/svg"
    >
      <path
        id="pathToAnimate"
        d="M-22.125 45.875C42.5625 54.3125 56.625 31.8119 98.8125 20.5625C129.589 12.3558 166.31 9.3125 183.188 17.7506C205.688 29 218.018 54.3125 239.438 54.3125C261.938 54.3125 284.438 34.625 312.562 20.5625C340.688 6.5 345.75 9.3125 377.25 9.3125C416.625 9.3125 470.062 45.875 489.75 54.3125C509.438 62.75 524.639 55.9499 529.125 40.25C534.75 20.5625 534.75 6.5 616.312 3.6875"
        stroke-width="5.625"
        stroke-linecap="round"
      />
      <defs>
        <linearGradient
          id="logoGradient"
          x1="3.18749"
          y1="14.9375"
          x2="548.812"
          y2="20.5625"
          gradientUnits="userSpaceOnUse"
        ></linearGradient>
      </defs>
    </svg>

Webpack generate complete separate builds per entrypoint

I had opened a question before but it seemed misinterpreted. I’m trying to make it so that webpack generates a build folder for every entrypoint containing all the chunks that are needed within that entrypoint.

For clarification;

What I have right now

build/
├─ standalone.js
├─ runtime.js
├─ 89.js
├─ product.js
├─ 399.js
├─ 191.js

What I want

build/
├─ standalone/
│  ├─ 191.js
│  ├─ 399.js
│  ├─ runtime.js
│  ├─ standalone.js
├─ product/
│  ├─ product.js
│  ├─ 89.js
│  ├─ runtime.js

You can see in the above that all files are split into their respective entrypoint containing all the chunk files that are needed to run that entrypoint.

What I’ve tried

I’ve tried setting two different entrypoints in my webpack.common.js config and then made the output be equal to ${pathData.chunk.name}/[name].[contenthash].bundle.js. However this doesn’t work. It results in two folders being generated with the standalone.js and product.js in them. But it the chunk files are still scattered in the build folder.

How can I make it so that it generates a folder for both entrypoints containing all the chunk files needed? Or do I need a completely different setup?