Webpack import causing massive bundle size even with sideEffects and unusedExports set

I have a typescript project (Designer project) that I am using to bundle files with another lerna managed project of “helper functions” and type definitions (Helper project). Each package.json of every package within my Helper project is marked as sideEffect: false. The main package I have exports from other packages in its main index.ts file. I think it must be typescript related because importing interfaces works fine but objects and functions start breaking things. Any help is appreciated.

My Helper project has a few files:

// index.ts
export * from './models'; // works sorta fine
export * from './helpers'; // doesn't work for sole export
// models.ts
// importing this and other interface exports works fine
export interface LFRepoWindow {
  [k: string]: any;
  webAccessApi?: WebAccessApi;
}
// importing this export causes the entire package to be imported 
// with all dependencies and 30+mb bundle size
export const notificationTypes = {
  warning: 'warning',
  error: 'error',
  success: 'success',
  information: 'information'
} as const;
// helpers.ts
// Importing this similarly causes all dependencies to bundle and 30+mb bundle size
export const getWebAccessInfo = function(checkFrames = false) {
  const windowList = checkFrames ? Array.from(window.frames) : [window, window.parent, window.top || undefined];
  const waWindow = windowList.find((w) => w?.webAccessApi !== undefined);
  return { waWindow, webAccessApi: waWindow?.webAccessApi, name: waWindow?.name };
}

My webpack config file is fairly complex as it is used to dynamically bundle folders from my Designer project but should be relatively understood from this snippet

const config: webpack.Configuration = {
  devtool: srcMap || env === 'DEV' ? 'inline-source-map' : undefined,
  entry: name.reduce((prev, cur, i) => {
    prev[cur] = path.resolve(curDir, 'src', cur + type[i], 'index');
    return prev;
  }, {} as { [k: string]: string }),
  mode: webpackENVMap[env],
  externals: {
  //   d3: 'd3'
    jquery: 'jQuery'
  },
  module: {
    rules: [
      {
        exclude: /node_modules/,
        test: /.[jt]sx?$/,
        use: [
          // {
          //   loader: 'babel-loader',
          //   options: { cacheDirectory: true },
          // },
          {
            loader: 'ts-loader',
          },
        ],
      },
      {
        test: /.html$/,
        use: [
          {
            loader: 'html-loader',
            options: {
              minimize: true,
              sources: {
              urlFilter: (attribute: string, value: string, resourcePath: string) => {
                if (//Forms/img//i.test(value)) {
                  return false
                }
              }
            } },
          },
        ],
      },
      {
        test: /.css$/,
        use: [
          {
            loader: MiniCssExtractPlugin.loader,
            options: {
              hmr: env !== 'DEV' ? true : false,
            },
          },
          'css-loader',
        ],
      },
    ],
  },
  optimization: {
    usedExports: true,
    sideEffects: true,
    moduleIds: 'deterministic',
    runtimeChunk: !splitChunks ? false : 'single',
    splitChunks: !splitChunks
      ? false
      : {
          cacheGroups: {
            vendor: {
              chunks: 'all',
              enforce: true,
              name(module: { context?: string }) {
                // get the name. E.g. node_modules/packageName/not/this/part.js
                // or node_modules/packageName
                const packageName = module.context?.match(/[\/]node_modules[\/](.*?)([\/]|$)/)?.[1]
                  || module.context || 'vendors';
                // npm package names are URL-safe, but some servers don't like @ symbols
                const packageChunkName = `npm.${packageName.replace('@', '')}`;
                vendorChunks.push(packageChunkName);
                return packageChunkName;
              },
              reuseExistingChunk: true,
              test: nodeModuleRegex,
            },
          },
        },
  },
  output: {
    filename: `[name]${splitChunks ? '.[' + hashType + ']' : ''}.js`,
    path: path.resolve(curDir, 'dist'),
    publicPath:
      env === 'DEV'
        ? 'http' + '://' + forms.DEV_HOST_NAME + ':' + forms.DEV_PORT
        : 'https' + '://' + forms.HOST_NAME + forms.FORMS_BUILD_LOCATION,
    // ? forms.PROTOCOL + '://' + forms.DEV_HOST_NAME + ':' + forms.DEV_PORT
    // : forms.PROTOCOL + '://' + forms.HOST_NAME + forms.FORMS_BUILD_LOCATION,
  },
  plugins: [
    new webpack.WatchIgnorePlugin({ paths: [/(css).d.ts$/] }),
    ...(shouldClean ? [new CleanWebpackPlugin()] : []),
    new MiniCssExtractPlugin({
      filename: env === 'PROD' ? '[name].css' : '[name].[' + hashType + '].css',
    }),
    ...name.map(
      n =>
        new HtmlWebpackPlugin({
          chunks: [n],
          filename: `${n}.html`,
          template: path.resolve(__dirname, '../assets', './index.html'),
        }),
    ),
    new webpack.ids.HashedModuleIdsPlugin(),
  ],
  resolve: {
    alias: {
      // '@root': path.resolve(__dirname, '../'),
    },
    fallback: {
      "tty": require.resolve("tty-browserify"),
      "path": require.resolve("path-browserify"),
      "util": require.resolve("util/"),
      "stream": require.resolve("stream-browserify"),
      "crypto": require.resolve("crypto-browserify"),
      "zlib": require.resolve("browserify-zlib"),
      "https": require.resolve("https-browserify"),
      "http": require.resolve("stream-http"),
      "vm": false, //require.resolve("vm-browserify"),
      "fs": false,
      "os": false,
      "worker_threads": false,
      "assert": false,
      "module": false,
      "console": false,
      "inspector": false,
      "esbuild": false,
      "@swc/core": false,
      "child_process": false,
      "constants": false,
    },
    extensions: ['.tsx', '.ts', '.js'],
  },
  stats: withMultiple ? 'minimal' : 'verbose',
  target: 'web',
}

How can I use v-model in base component with vee-validate?

I want to validate using vue vee-validate and baseinputs. But I cannot use v-model where I call the component.

my TextInput Component.

<template>
  <div
    class="TextInput"
    :class="{ 'has-error': !!errorMessage, success: meta.valid }"
  >
    <label :for="name">{{ label }}</label>
    <input
      :name="name"
      :id="name"
      :type="type"
      :value="inputValue"
      :placeholder="placeholder"
      @input="handleChange"
      @blur="handleBlur"
    />

    <p class="help-message" v-show="errorMessage || meta.valid">
      {{ errorMessage || successMessage }}
    </p>
  </div>
</template>

<script>
import { useField } from "vee-validate";

export default {
  props: {
    type: {
      type: String,
      default: "text",
    },
    value: {
      type: String,
      default: "",
    },
    name: {
      type: String,
      required: true,
    },
    label: {
      type: String,
      required: true,
    },
    successMessage: {
      type: String,
      default: "",
    },
    placeholder: {
      type: String,
      default: "",
    },
  },
  setup(props) { 
    const {
      value: inputValue,
      errorMessage,
      handleBlur,
      handleChange,
      meta,
    } = useField(props.name, undefined, {
      initialValue: props.value,
    });

    return {
      handleChange,
      handleBlur,
      errorMessage,
      inputValue,
      meta,
    };
  },
};

App.vue file where I call the component

<template>
  <div>
    {{ test }}
    <Form
      @submit="onSubmit"
      :validation-schema="schema"
      @invalid-submit="onInvalidSubmit"
    >
      <TextInput
        name="name"
        type="text"
        label="Full Name"
        placeholder="Your Name"
        success-message="Nice to meet you!"
        v-model="test"
      />
    
      <button class="submit-btn" type="submit">Submit</button>
    </Form>
  </div>
</template>

<script>
import { ref } from "vue";
import { Form } from "vee-validate";
import * as Yup from "yup";
import TextInput from "./components/TextInput.vue";

export default {
  name: "App",
  components: {
    TextInput,
    Form,
  },
  setup() {
    const test = ref("asda");
    function onSubmit(values) {
      alert(JSON.stringify(values, null, 2));
    }

    function onInvalidSubmit() {
      const submitBtn = document.querySelector(".submit-btn");
      submitBtn.classList.add("invalid");
      setTimeout(() => {
        submitBtn.classList.remove("invalid");
      }, 1000);
    }
    const schema = Yup.object().shape({
      name: Yup.string().required(),
      email: Yup.string().email().required(),
      password: Yup.string().min(6).required(),
      confirm_password: Yup.string()
        .required()
        .oneOf([Yup.ref("password")], "Passwords do not match"),
    });

    return {
      onSubmit,
      schema,
      onInvalidSubmit,
      test,
    };
  },
};
</script>

where I wrote in v-model ="test" doesn’t work. I tried to send it with emit but I couldn’t.

So, in summary, let the component I validate perform the validation process, but I can use the v-model where I call the component.

Return propertype enum typescript

I have some function like this

  public CustomerEditType(customer: Customer): CustomerEditType {
    if (customer.company) {
      if (customer.vatNumber) {
        return CustomerEditType.COMPANYVAT;
      } else {
        return CustomerEditType.COMPANYNOVAT;
      }
    } else {
      return CustomerEditType.PRIVATE;
    }
  }

The problem I have here i dont know how to shorter this function, maybe some inline?

Using Axios to send a token to the backend

I am new to this

I am writing a Vue app that connects to a WordPress backend and I need to log in. I am using a plugin called Simple JWT-Login and I am able to send the email and password to the back end and i get the JWT back. But trying to log in and sending the jWT back to the back end gets me an error Bad Request.
Here is the function that is supposed to handle the login

    async login(){
      try{
        const response = await axios.post('/?rest_route=/simple-jwt-login/v1/auth&email=email&password=password', 
          {
            email: this.email,
            password: this.password,
          }
        );
        const token = response.data.data.jwt
        localStorage.setItem('token', token)
        console.log(token)
        const login = await axios.get('/?rest_route=/simple-jwt-login/v1/autologin&JWT=token')
        console.log(login)
        // this.$router.push("/");
      } catch(err){
        console.log(err)
        // if(err.response.status === 400){
        //   this.error = "Wrong credentials! Please make sure"
        // }
      } finally{
          
      }
    }

How to read Spring Boot properties (application.properties) from Javascript file?

Is there a way to read Spring properties from HTML or JavaScript file? I might convert the HTML to JSP and read it. But I am looking for a solution with HTML or JavaScript.

I have values in application.properties file in /resources/config, and I like to read this from my HTML or JavaScript file sits under /resources/static.

test.value=1234

Is this possible? Are there any other suggestions if reading it from plain HTML or JS is not possible?

How to enable mixed content into your Next.js app with 3rd party npm

My web app is HTTPS but the targeted resource is HTTP. As a result, facing mixed-content issue:

Mixed Content: The page at ‘https://app-website-dev.shikho.net/student/video-archive/a74c812b-82dd-417c-b07e-c4544911acac’ was loaded over HTTPS, but requested an insecure resource ‘http://res.cloudinary.com/cross-border-education-technologies-pte-ltd/image/upload/v1643522121/eofmak1yhic4n8chsrlo.pdf’. This request has been blocked; the content must be served over HTTPS.

I can fix the issue from browser settings but want something inside the code instead from browser GUI (as all the users are not technical in this site).

How can i achieve this from code level? So far I’ve visited CSP: block-all-mixed-content. May be something like syntax Content-Security-Policy: block-all-mixed-content; has to use into code?

Here is my code:

import React from 'react';
import Viewer, {Worker} from '@phuocng/react-pdf-viewer';
import '@phuocng/react-pdf-viewer/cjs/react-pdf-viewer.css';

function StdPDFViewer({url}) {
    return (<div className="pdf-container"
                 style={{
                     backgroundColor: 'aliceblue',
                     border: '1px solid rgba(0, 0, 0, 0.3)',
                     display: 'flex',
                     flexDirection: 'column',
                     height: '100%',
                 }}>
        <Worker workerUrl="https://unpkg.com/[email protected]/build/pdf.worker.min.js">
            <div id="pdfViewer" style={{height: '100vh'}}>
                <Viewer fileUrl={url}
                        defaultScale={1}
                        httpHeaders={{key: 'C6590A86-50504136-B572A792-D36E0771'}}
                        withCredentials={true}/>
            </div>
        </Worker>
    </div>);
}

export default StdPDFViewer;

I’m using React-PDF-Viewer where the documentation has options like httpHeaders. Please have a look.

Thanks for reading.

How to set s3 bucket policy only give s3:ListBucket to IdentityPoolId in javascript

How to set json policy under s3 bucket permissions to give only “s3:ListBucket” access to the below IdentityPoolId.

“Action”: “s3:ListBucket”, “Resource”: “arn:aws:s3:::New-customers”, then it gives as public access, but want to restrict and only available access to IdentityPoolId

var bucketName = "New-customers";
var bucketRegion = "ap-south-1";
var IdentityPoolId = "ap-south-1:xxxxxxxxxxxxxxxxxxxxxxxx";

 AWS.config.update({
                region: bucketRegion,
                credentials: new AWS.CognitoIdentityCredentials({
                    IdentityPoolId: IdentityPoolId
                })
            });

            var s3 = new AWS.S3({
                apiVersion: '2006-03-01',
                params: {Bucket: bucketName}
        });
        
AWS.config.update({correctClockSkew: true});

How to make it using Regex in Javascript? [closed]

General Format Rules 
1: First always $ then numenter image description hereber, no space between $ and number ($100 - $100,000) 
2: Space between number and line ($100 - $100,000) 
3 :Full number, thousands, no Ks, incorrect example -> $100 – $100K) 
4 :Values above certain value and without any limitations, please always use this sign  >, correct example -> > $1,000,001

Slick.js is not loading in vue component

I have made a Carousel Component in vue. I have used Slick.js slider. Now problem is that slick.js is not being loaded and I’m facing following error.

jquery-3.3.1.slim.min.js:2 Uncaught TypeError: $(…).slick is not a
function

Even I have used Slick.js CDN but still facing same error. In normal html file it works properly. But in vue I’m facing this issue.I have checked jquery is also working fine. Only slick.js is not being load. Here is my vue component

<template>
   <section class="feature-sound">
     <div class="container">
       <div class="tile-text-area">
         <h2 class="mb-0 cairo-title">Explore Sounds by</h2>
       </div>
          <ul class="list-unstyled tab-list">
             <li><div class="explore-tab-1 tab-item active">Location</div></li>
             <li><div class="explore-tab-2 tab-item ">Categories</div></li>
             <li><div class="explore-tab-3 tab-item ">Tags</div></li>
          </ul>

             <div class="explore-tab-1-area animate__animated animate__fadeIn">
                <section class="regular1 slider">
                <div class="tab-slider-element r-r-border">
                 <img :src="'assets/img/abdeen-01.png'">
                 <a class="slider-link" href="#">Abdeen</a>
                </div>
                <div class="tab-slider-element r-r-border">
                  <img :src="'assets/img/abdeen-01.png'">
                 <a class="slider-link" href="#">Abdeen</a>
                </div>
                <div class="tab-slider-element r-r-border">
                  <img :src="'assets/img/abdeen-01.png'">
                 <a class="slider-link" href="#">Abdeen</a>
                </div>
                <div class="tab-slider-element r-r-border">
                  <img :src="'assets/img/abdeen-01.png'">
                 <a class="slider-link" href="#">Abdeen</a>
                </div>
                <div class="tab-slider-element r-r-border">
                  <img :src="'assets/img/abdeen-01.png'">
                 <a class="slider-link" href="#">Abdeen</a>
                </div>
                <div class="tab-slider-element r-r-border">
                  <img :src="'assets/img/abdeen-01.png'">
                 <a class="slider-link" href="#">Abdeen</a>
                </div>
                <div class="tab-slider-element r-r-border">
                  <img :src="'assets/img/abdeen-01.png'">
                 <a class="slider-link" href="#">Abdeen</a>
                </div>
                <div class="tab-slider-element r-r-border">
                  <img :src="'assets/img/abdeen-01.png'">
                 <a class="slider-link" href="#">Abdeen</a>
                </div>
                <div class="tab-slider-element r-r-border">
                  <img :src="'assets/img/abdeen-01.png'">
                 <a class="slider-link" href="#">Abdeen</a>
                </div>
                <div class="tab-slider-element r-r-border">
                  <img :src="'assets/img/abdeen-01.png'">
                 <a class="slider-link" href="#">Abdeen</a>
                </div>
                <div class="tab-slider-element r-r-border">
                  <img :src="'assets/img/abdeen-01.png'">
                 <a class="slider-link" href="#">Abdeen</a>
                </div>
              
              </section>
             </div>
             <div class="explore-tab-2-area   animate__animated animate__fadeIn">
                <section class="regular2  slider">
                <div class="tab-slider-element r-r-border">
                   <button class="btn slider-inner-btn">ECONOMIC</button>
                </div>
                <div class="tab-slider-element r-r-border">
                   <button class="btn slider-inner-btn">SOCIAL</button>
                </div>
                <div class="tab-slider-element r-r-border">
                   <button class="btn slider-inner-btn">RELIGIOUS</button>
                </div>
                <div class="tab-slider-element r-r-border">
                  <button class="btn slider-inner-btn">TRANSPORTATION</button>
                </div>
                <div class="tab-slider-element r-r-border">
                   <button class="btn slider-inner-btn">WILDLIFE</button>
                </div>
                <div class="tab-slider-element r-r-border">
                  <button class="btn slider-inner-btn">ECONOMIC</button>
                </div>
                <div class="tab-slider-element r-r-border">
                   <button class="btn slider-inner-btn">ECONOMIC</button>
                </div>
                <div class="tab-slider-element r-r-border">
                   <button class="btn slider-inner-btn">ECONOMIC</button>
                </div>
                <div class="tab-slider-element r-r-border">
                  <button class="btn slider-inner-btn">ECONOMIC</button>
                </div>
                <div class="tab-slider-element r-r-border">
                   <button class="btn slider-inner-btn">ECONOMIC</button>
                </div>
                <div class="tab-slider-element r-r-border">
                  <button class="btn slider-inner-btn">ECONOMIC</button>
                </div>
                <div class="tab-slider-element r-r-border">
                   <button class="btn slider-inner-btn">ECONOMIC</button>
                </div>
                <div class="tab-slider-element r-r-border">
                   <button class="btn slider-inner-btn">ECONOMIC</button>
                </div>
                <div class="tab-slider-element r-r-border">
                  <button class="btn slider-inner-btn">ECONOMIC</button>
                </div>
                <div class="tab-slider-element r-r-border">
                   <button class="btn slider-inner-btn">ECONOMIC</button>
                </div>
                <div class="tab-slider-element r-r-border" >
                  <button class="btn slider-inner-btn">ECONOMIC</button>
                </div>
              </section>
             </div>
             <div class="explore-tab-3-area  animate__animated animate__fadeIn">
                <section class="regular3 slider">
                
                <div class="tab-slider-element ">
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  
                </div>
                <div class="tab-slider-element ">
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  
                </div>
                <div class="tab-slider-element ">
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  
                </div>
                <div class="tab-slider-element ">
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  
                </div>
                <div class="tab-slider-element ">
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  
                </div>
                <div class="tab-slider-element ">
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  
                </div>
                <div class="tab-slider-element ">
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  
                </div>
                <div class="tab-slider-element ">
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  
                </div>
                <div class="tab-slider-element ">
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  <div class="tab-slider-small-box r-r-border">
                    
                  </div>
                  
                </div>
              
              </section>
             </div>
           </div>
   </section>
</template>

<script>
export default {
  name: "ExploreSound"
}
</script>

<style scoped>

</style>

here us js code of slick

  $('.regular1').slick({
          dots: false,
          infinite: false,
          speed: 300,
          slidesToShow: 6,
          slidesToScroll: 4,
          responsive: [
            {
              breakpoint: 1024,
              settings: {
                slidesToShow: 4,
                slidesToScroll: 3,
              }
            },
          
            {
              breakpoint: 576,
              settings: {
                slidesToShow: 2,
                slidesToScroll: 2
              }
            }
            // You can unslick at a given breakpoint now by adding:
            // settings: "unslick"
            // instead of a settings object
          ]
});

   $(".regular2").slick({
        dots: false,
        infinite: true,
        slidesToShow: 5,
        navs:false,
        slidesToScroll: 3
      });
   $(".regular3").slick({
        dots: false,
        infinite: true,
        slidesToShow: 6,
        navs:false,
        slidesToScroll: 3
      });
   
  }); 

Filter and sub array to match the case with filter method in JavaScript [duplicate]

I want to iterate an array inside an object and check if it matches one of the criteria. Here is a single object that I want to iterate the genres array and check if one of the criteria matches it. (This is one object, while there are plenty more that can be filtred.)

{
            "id": 6,
            "title": "Ratatouille",
            "year": "2007",
            "runtime": "111",
            "genres": [
                "Animation",
                "Comedy",
                "Family"
            ],
            "director": "Brad Bird, Jan Pinkava",
            "actors": "Patton Oswalt, Ian Holm, Lou Romano, Brian Dennehy",
        },

And here is my method until now, but don’t know how to iterate:

const filtredMovies = movies.filter((item) => item.genres === "Family");

Given the advertising id, can I get a user’s interests according to google?

I am working on a website based around the gimmick of knowing who the user is already on the first visit to the site. So I want to use JavaScript to query some advertising API to get the information they already have about the user coming in. Is this possible?

For instance, if I can get the advertising ID (by finding the associated cookie on my website) that Google (or anyone else) has put there with the ad, is it possible to access what Google thinks the user is interested in? That is, given the advertising id, is their an API I can call to get the info google says they have about them? Like how I can tell what they think about me by going to https://adssettings.google.com/authenticated, can I do that for any user automatically? Information like “Likes football, volleyball, coding”?

Ideally this would be done via an HTTPS request via Javascript or some Javascript API.

How to add media mobile query in JavaScript code for drag slide carousel

I have a drag to slide card carousel, now two and half cards showing in the main display in desktop, I need one and half cards display in 550 media query mobile view, please add 550 media query in my script code to display 1.2 cards, thanks in advance

<script>

window.sr = ScrollReveal();
var swiper = new Swiper('.swiper-container', {
  speed: 300,
  parallax: true,
  preventClicks: true,
  spaceBetween: 6,
  slidesPerView: 2.8, 
});

$(function() {
    FastClick.attach(document.body);
});
</script>

How to render HTML from database in react?

I am working on making custom webpages with the help of Grapesjs. I want to render the html page in react js which has been been saved by the grapesjs editor in the database. Following is the format in which the data is being saved.

Right now I just able to get the html code in the inspect window, but how can i render it on the page?

import React from "react";
import axios from "axios";
// import {renderWebpage} from "../actions/webpage"

export const Page: React.FC = () => {
  const renderWebpage = axios
    .get("http://localhost:8080/61ea7fd2268f37443ca4d59a")
    .then((response) => {
      console.log("response", response);
      console.log(response.data, "data");
    });

  return <div>demo</div>;
};