Minimize property names with Webpack

Our Vue 2.x.x application, written in typescript, needs to be structured into modules such as /users, /articles, /reports, following a micro frontend architecture.

We are looking for a solution that allows us to load these modules dynamically based on user permissions. After researching, we decided to opt for SystemJS. Here is an example of how we plan to implement it:

export const ApplicationModuleService = {
   
    
        createModule(name: string, url: string, activeWhen = "/", props = {}): RegisterApplicationConfig {
            return {
                name,
                app: () => window.System.import(url), //system js is loading from cdn. in global.d has definition
                activeWhen,
                customProps: props
            }
        }
    }

Although we have imported SystemJS from CDN, when transpiling with webpack, we face challenges using System.import and are forced to utilize the window object instead.

Attempting to use System.import results in webpack transpiling it into a shortened property like l.import(...). We have tried creating global properties with webpack plugins like DefinePlugin or ProvidePlugin, but without success.

If anyone has encountered this issue before and found a workaround, we would greatly appreciate your insights.

Answer №1

If you're already using webpack, there's no need to rely on System.js as your module loader.

Webpack comes equipped with lazy loading module capabilities out of the box.

All you have to do is utilize import('path/to/my/lazy/module'), which returns a Promise that resolves once the module has loaded. Webpack takes care of the rest for you.

Your code should resemble this:

export const ApplicationModuleService = {
  createModule(name: string, url: string, activeWhen = '/', props = {}): RegisterApplicationConfig {
    return {
      name,
      app: () => import('path/to/lazy/module')
      activeWhen,
      customProps: props,
    };
  },
};

If you need CDN support, you can specify the publicPath option.

For more information, check out this link

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

Bundle a module that includes node modules using webpack

Query I'm looking to modify a JavaScript library that is open source. By utilizing webpack and npm locally, what are my options for altering a local module and integrating it into a project instead of using a public npm module downloaded from the reg ...

Angular 15 experiences trouble with child components sending strings to parent components

I am facing a challenge with my child component (filters.component.ts) as I attempt to emit a string to the parent component. Previously, I successfully achieved this with another component, but Angular seems to be hesitant when implementing an *ngFor loop ...

Exporting declarations and different export types within a TypeScript ambient module

I am currently working on adding specific types for the config module in our application. The config module is generated dynamically from a JSON file, making it challenging to type. Since it is a node module, I am utilizing an ambient module for the typing ...

Configure parameters for Shopware navigation path

When initializing my Shopware 6 plugin, I encountered an issue with the Vue Router not recognizing a standard ID on the first page. routes: { list: { path: 'list/:id', component: 'plugin-list' }, ...

Contrasting type[] (array) with [type] (tuple)

If we imagine having two interfaces: interface WithStringArray1 { property: [string] } interface WithStringArray2 { property: string[] } Let's define variables of these types: let type1:WithStringArray1 = { property: [] } let type2:Wit ...

What distinguishes Angular directives as classes rather than functions?

When using Ng directives within HTML tags (view), they appear to resemble functions that are called upon rather than instances of a class. It almost feels like they could be static methods that can be invoked without an instance of a class. Comin ...

Resolving Cross-Origin Resource Sharing issues with AWS SDK (Lightsail API) and Vue.js

I'm currently working on a small vue.js application that utilizes aws-sdk to retrieve information about Lightsail instances. However, I keep encountering this issue. :8081/#/:1 Access to XMLHttpRequest at 'https://lightsail.us-west-2.amazonaws.c ...

Tips for simulating localStorage in TypeScript unit testing

Is there a method to simulate localStorage using Jest? Despite trying various solutions from this post, none have proven effective in TypeScript as I continue encountering: "ReferenceError: localStorage is not defined" I attempted creating my ...

Guide on creating a 4-point perspective transform with HTML5 canvas and three.js

First off, here's a visual representation of my objective: https://i.stack.imgur.com/5Uo1h.png (Credit for the photo: ) The concise question How can I use HTML5 video & canvas to execute a 4-point perspective transform in order to display only ...

Combining data from various API calls into one cohesive array using RXJS

My RXJS Pipeline is structured as follows: const logs: number[] = [1, 2, 3, 4]; const url = 'http://some-url-here.com'; const pipeline = from(logs).pipe( switchMap(logId => this.callEndpoint(url, logId).pipe(map(response => response. ...

Tips for notifying the user about incorrect login credentials in Ionic 3

I'm attempting to implement a notification system using showAlert to inform users when they enter an incorrect email or password, but I'm having difficulty achieving this using try and catch statements Would it be feasible for me to use try and ...

Switch up your vuecomponents with Vue.js toggling!

I am currently working on a simple Vue application and I am still getting the hang of Vue.js. In my project, I have two Vue components that I want to toggle between upon clicking a button. My question is whether it is possible to achieve this by using sc ...

Typescript provides the flexibility to construct incomplete or partially valid objects

My attempt to create a partial helper function in Typescript led me to an incorrect version that went unnoticed by Typescript: Typescript version: 5.2.2 type A = { a: number; b: string }; // incorrect const buildPartialBad = (key: keyof A, val: A[keyof A ...

How to pass route parameters using v-link in Vue Router

Within the Parent.vue file, I have included this anchor tag: <a v-link="{ path: '/somepath/somesubpath', query: { messageId: 999}}"> Here </a> And also this one: <a v-link="{ path: '/somepath/somesubpath', params: { me ...

Unexpected token @ while using Angular2 with jspm and gulp for typescript compilation

Recently, I've delved into learning about Angular 2 and its accompanying technologies. In an attempt to create minified and "compiled" versions of my .ts files, I started using gulp-jspm-build. However, I encountered an error that has left me stumped. ...

Dealing with side effects in react/redux: Best practices and tips

Trying to find the best way to integrate an async side-effects handler into my react/redux setup has been quite a challenge. In my react-router-driven application, all the main containers at root level are smoothly dispatching actions and receiving update ...

Automatically pass on parameters from a universal function

If I have an object with functions that return numbers: const obj = { foo() { return 1; } bar() { return 2; } baz(num: number) { return num; } } The expected output of typeof obj would be: { foo: () => number; bar: () => number; baz ...

Angular HttpClient not recognizing hashtag

I'm trying to make a REST API call, but running into issues with the developerId parameter being sent incorrectly: let developerId = "123#212"; let url = \`\${Constants.BASE_URL}\${marketId}/developers/\${developerId}\`; retur ...

Utilize Vue to access and read a file stored in the current directory

I am attempting to retrieve data from a text file that is located in the same directory as my .vue file. Unfortunately, I am encountering an issue where the content of the text file is not being displayed in both Chrome and Firefox. Instead, I am seeing th ...

Tips for sending a post request using Angular 4

I'm currently facing an issue while attempting to execute a post request using Angular 4 to transmit lat and lng parameters: let data = {lat: this.newLat, lng: this.newLng}; this.http.post(url, data) .map(response => response.json()) .subscri ...