Webpack Plugin System for Building Web Applications

In the context of my project, I am currently working on a product utilizing Symfony for the back-end and react/react-router for the front-end, all connected via Webpack. My plan is to structure my app into different "extensions", which would consist of a "core" bundle and additional bundles with unique features for the product.

I strive for the same level of extensibility in the front-end as I have in the back-end. I want to be able to seamlessly integrate new React components from the extending bundles into the existing set of components within the "CoreBundle".

Despite this ambition, it appears that Webpack's tight encapsulation may hinder the creation of such a plugin system. Is it feasible to have multiple bundles with individual Webpack configurations, yet have interconnected JavaScript code that allows for the development of a plugin system? The ultimate objective is to work on JS for one Bundle independently while also being able to utilize pre-compiled JS resources from another Bundle simultaneously.

Answer №1

To achieve this, consider utilizing the DllPlugin and DllReferencePlugin in your webpack configuration.

The DllPlugin is a useful tool for creating a separate bundle containing only libraries. It generates a manifest.json file that the DllReferencePlugin uses to resolve dependencies.

For detailed information, visit:

https://webpack.js.org/plugins/dll-plugin/

In my scenario, I consolidate all vendor libraries (such as React, Flux) into one build using DllPlugin, then reference it in another webpack config which bundles React components while importing React and other libraries through DllReferencePlugin.

This is an example of my webpack.dll.js configuration file:

var path = require("path");
var webpack = require("webpack");

module.exports = {
  entry: {
    libs: [path.join(__dirname, "common", "lib.js")]
  },
  output: {
    path: path.join(__dirname, "dist", "dll"),
    filename: "[name].dll.js",
    library: "[name]"
  },
  plugins: [
    new webpack.DllPlugin({
      path: path.join(__dirname, "dll", "[name]-manifest.json"),
      name: "[name]",
      context: path.resolve(__dirname, "common")
    }),
  ]
};

In my main webpack.config.js, I utilize the DllReferencePlugin as follows:

 new webpack.DllReferencePlugin({
      context: path.resolve(__dirname, "common"),
      manifest:require('./dll/libs-manifest.json')
    })

By creating multiple Dlls with separate webpack configurations according to your needs, you can efficiently manage code splitting and reference dll's in different webpack bundles as required.

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

Symfony allows for unique field validation for one-to-many relationships

My Request entity contains multiple Interventions structured as follows: Request.php /** * @ORM\OneToMany(targetEntity=Intervention::class, mappedBy="request") * @Assert\Count(min=1, max=3) * @Assert\Valid ...

What is the best way to create a unique page transition animation using Framer Motion and Next.js?

I am currently using Next.js, React, TypeScript, and Framer Motion in my project. I have successfully implemented page transitions from right to left when changing pages within my _app.tsx file. However, I am facing an issue with the arrow navigation; both ...

Adjust the dimensions of the react-dropdown-tree-select element to better fit your needs

Hey there, I'm a beginner web developer currently working on a tree-based dropdown menu. Check out the documentation here To see it live in action, visit the example here I'm trying to adjust the height and width of the "Search/DropDown bar" in ...

Utilizing StyleFunctionProps within JavaScript for Chakra UI Enhancements

I need help figuring out how to implement StyleFunctionProps in my Chakra UI theme for my NextJS project. The documentation on Chakra's website provides an example in Typescript, but I am working with Javascript. Can someone guide me on adapting this ...

Experiencing difficulties establishing a connection between the React client and Node.js server using SocketIO

I am currently getting familiar with socketIO and have successfully set up a basic nodejs server. However, I am facing an issue where my nextJS app is unable to connect to the server as expected. Despite no errors being displayed, the messages that should ...

Updating subdata in an array using Reactjs handleChange

I am facing an issue with my handleChange function. While I can easily change data in the same directory without any problem, I'm struggling to update sub-data. I would like to find a clean solution for this without having to add extra functions withi ...

Uninstalling Vue.js from a Rails application using webpack

After using the command line to install Vue.js, I'm now looking to uninstall it. Is there a way to revert the installation process? bundle exec rails webpacker:install:vue Any guidance on removing Vue.js would be greatly appreciated. ...

Tips for rendering the title based on the specific ID provided by the API in nextJS

There is an issue I am facing. I only want to show the "title" based on the ID, but currently all the "titles" are showing up at once. You can see it in the image below: https://i.stack.imgur.com/89D6L.png Here's my code: const getData = () => { ...

Centering the logo using Material-UI's alignment feature

Need help centering a logo in my login form using Material-UI. Everything else is centered except for the logo, which is stuck to the left side of the card. I've tried adding align="center" and justify="center" under the img tag, but it's still ...

Having trouble deploying my MERN app on Vercel because I keep getting a "NOT FOUND" error message

I am encountering an issue while attempting to deploy my MERN App on Vercel - I keep receiving a "NOT FOUND" error. Interestingly, when I set NODE_ENV to PRODUCTION, the app works fine and serves the static files locally when running npm start. However, t ...

Next JS now includes the option to add the async attribute when generating a list of script files

We are currently working on a nextJs application and are looking to add asynchronous functionality to all existing script tags. Despite numerous attempts, we haven't been successful in achieving this. Can anyone provide some guidance or assistance? &l ...

what is the best way to eliminate comments from nested arrays when using useReducer?

Can someone help me figure out how to use useReducer and useContext to manipulate global state? I specifically need to know how to delete comments using useReducer. Data Structures View the interface image here Sample Data Array export const listsData:IDa ...

Tips for aligning a Material UI FAB button in the center and keeping it in the center while resizing the window

Is there a way to center a MaterialUI FAB button and keep it centered while resizing the window? The current positioning is not centered, as seen in the screenshot below, and it does not adjust with window size changes. Below is the code for the current F ...

The issue with Next.js is that cookies are not being transmitted along with fetch requests, even when credentials are

I've been developing a Next.js application that originally started as a regular React app created using create-react-app. I'm facing an issue where the cookies are not being sent with my fetch request to the server, despite setting credentials: & ...

The declared type 'never[]' cannot be assigned to type 'never'. This issue is identified as TS2322 when attempting to pass the value of ContextProvider using the createContext Hook

I'm encountering an issue trying to assign the state and setState to the value parameter of ContextProvider Here's the code snippet:- import React, { useState, createContext } from 'react'; import { makeStyles } from '@material-ui ...

Adjusting the default format_date for SonataSonata's default

After successfully setting up the SonataIntlBundle bundle, I noticed that the default format_date displays dates as day-number month-name year. {{ date_time_object | format_date }} => '1 août 2011'Source Now, I am looking to personalize thi ...

React Native throws an error when trying to convert a JSON value of type NSNULL, which is '<null>', to a valid URL

Currently, I am working on an app that requires me to access the device photo gallery in order to replace a default image displayed on the screen. The default value is set to null, which seems to work fine on Android but throws an error on iPhone devices. ...

What is the best way to send a socket.io message to a particular user who is currently

When using socket.io with express and typescript, I am facing an issue where emitting to a particular logged-in user is not working. However, the rest of the functionality works fine such as when a new user joins. In my App.ts backend file, the code looks ...

Struggling with a React Native build warning problem?

Upon executing react-native init reactApp, I encountered a warning stating that npm WARN <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ceef9fdffe8b1f2fde8f5eaf9dcacb2afa5b2ae">[email protected]</a> requires a pe ...

The additional cost associated with using a React hook is called the "

Our system includes a theme context provider that passes down a theme to all child components, calculated based on the device's dimensions. We can easily access these values using the useTheme hook in any component. In addition, we have a constants f ...