Combining external resources for shared use among various modules with webpack

Currently, I am developing modules to be integrated into a project. These modules share common dependencies, resulting in the duplication of packaged dependencies within the bundle when using webpack. To resolve this issue, I have identified and set these dependencies as external.

For example:

external: {
    'react':'react',
    'react-dom':'react-dom'
}

However, I am currently faced with the challenge of consolidating these dependencies into a single common JS file that can be utilized across all modules.

Answer №1

Here is how you should configure externals in your webpack setup:

// Make sure to exclude React from the bundle, include only react and react-dom
externals: {
  react: {
    root: 'React',
    commonjs2: 'react',
    commonjs: 'react',
    amd: 'react',
    umd: 'react',
  },
  'react-dom': {
    root: 'ReactDOM',
    commonjs2: 'react-dom',
    commonjs: 'react-dom',
    amd: 'react-dom',
    umd: 'react-dom',
  },
},

You can then use these external libraries in your main application.

If this doesn't match your situation, it would be helpful to have more details.

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

Finding the count of childNodes within a div using Selenium

I've been grappling with this issue for the majority of today; I'm trying to tally up the number of childNodes within a parent div. It's essentially mimicking a list where each childNode represents a row that I want to count. The HTML struct ...

Updating state: Removing a specific individual from an array of objects when a button is clicked

I am currently working on a code snippet where I aim to remove a specific person from an organizational chart once the delete button next to their name is clicked. However, I am encountering an issue where clicking any delete button results in all 5 people ...

Having difficulties retrieving footer Fields using cheerio library

https://i.sstatic.net/TlsIZ.png When utilizing node and cheerio to scrape the header and footer of a table, I encountered an issue with my code. Below is the entire table HTML and my code snippet: async function getTableFooter(html) { const $ = cheerio ...

Redux actions do not cooperate with functions, preferring to be implemented inline instead

I am a beginner in Redux and JavaScript and just came across this issue, When I use the line dispatch({type: 'REQUEST_START'}); it works fine, but when I write it like this: dispatch(requestStart); No actions are being fired! Any suggestions ...

Applying Media Queries Based on Element Height

Situation: In my scenario, there is an image with two buttons below it, all of which share the same width. Issue: When the viewport is too wide horizontally, the buttons are not visible without scrolling down. This poses a challenge for tablets and small ...

Excessive data flooding the console through Socket.io until the Payload reaches an unsustainable size

This snippet of code forms part of a chat application developed using React Native, functioning through a socket.io server. const Message = ({text, isSent}) => { return ( <View style={[styles.messageContainer, isSent ? styles.sentMessage : styl ...

Having challenges retrieving information from MySQL in AngularJS

As a beginner in angularJS, I am trying to display all customers from MySQL. Here is the code I have written in the controller and service: app.controller('CustomersController', function ($scope, customersService, $http) { init(); function ini ...

Experimenting with Extjs compatibility using Selenium

I am currently in the process of testing an extjs application using Selenium. I am utilizing Selenium IDE for Firefox and Javascript with Eclipse on Chrome. Despite spending countless hours searching for a solution to my problem, I have been unable to iden ...

Use PhpStorm and node-watch to monitor changes, compile files, and deploy them to the server effortlessly

I am currently using the node-watch script to monitor any changes in files and then rebuild project files by concatenating them together. Although the files are successfully being built, they are not automatically uploading to the server unless I manually ...

Use the loopback repository from one controller in a different controller

When I try to access the 'productRepository' property in the test.controller.ts file, an error occurs. import {repository} from '@loopback/repository'; import {ProductRepository} from '../repositories'; export class TestContro ...

Exploring the capabilities of Jasmine 2.0 by testing an AngularJS factory method that returns a promise

When attempting to test a function that returns a promise, I encounter the following error: "Error: Timeout - Async callback was not invoked within the timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. " The specification I am using is as follo ...

Display a pop-up message following the successful addition of an item to the cart across

Running a WooCommerce webshop, I want a popup to appear when customers click on the "Add to Cart" button. The code I have written works perfectly in Google Chrome but doesn't function in Safari due to page reload issues. I suspect that the problem li ...

Is the file corrupt using node.js?

Looking for ways to determine if a file is corrupted using node.js? I have attempted various File System methods, such as fs.readFile, fs.open, and fs.access, but all of them are showing an OK status. However, I am confident that my file is corrupted base ...

What's the issue with reducers receiving a Function instead of an Object in Redux?

I encountered an error in my react and redux project but I am unable to figure out how to fix it. Here is the error message: The reducer received unexpected type "Function" as the previous state. It was expecting an object with keys: "posts", "sidebar" ...

Executing a background.js function in response to an event trigger within the active tab in a Chrome extension

I am facing an issue where I am getting an error saying "resetTime is not defined" when running the code below. I have tried passing the function as an argument, but that did not solve the problem. Do I need to come up with a new logic to reset the time ...

What is the best method to retrieve information from a nested JSON array?

Whenever a user submits data, I receive it in a nested JSON array format and I must extract that information. For example, the data could range from question_1 to question_5 in one submission, and then from question_1 to question_9 in another submission. ...

Node.js require function not functioning as anticipated

After using Node and node express generator to create node express code successfully, I encountered an issue when attempting to deploy it to the server. By default, there are a couple of files present: .bin/www ( containing var app = require('../app ...

Filtering content using a checkbox

I am trying to customize this code so that the displayed results show the values of all checkboxes selected. For example, if I check "computers" and "video-games," only result 3 should be shown. What steps should I take to implement this modification? &l ...

angular-chart custom tooltip positioning issue

Hello everyone! I'm having trouble fixing the tooltip position when hovering over a point. I've searched through various posts on StackOverflow and have tried all the examples provided in my implementation: https://github.com/chartjs/Chart.js/tr ...

Navigating between pages in a multi-page setup using vue.js: A comprehensive guide

I came across a helpful post at this link about implementing multiple pages in Vue.js CLI. After setting up multiple pages, I was excited to test it out. However, I encountered an issue when trying to access the different pages from the URL http://localho ...