Setting up webpack for React to utilize multiple entry points and outputs

Having some trouble configuring the server to handle multiple entries and outputs. The application utilizes Zurb Foundation, jQuery, and React.

I'm aiming to exclude jQuery and foundation from the bundle.js file, while also creating a separate bundle for React.

Although Webpack validates and the server starts without issue, nothing is displayed on the console and an error stating "ReferenceError: webpackJsonp is not defined" appears.

When using a single entry, everything works fine. The issue arises when attempting to incorporate multiple entries.

webpack.config

var webpack = require('webpack');
var path = require('path');
var CommonsChunkPlugin = require('./node_modules/webpack/lib/optimize/CommonsChunkPlugin');

module.exports = {
    entry: {
        main: ['script!jquery/dist/jquery.min.js',
        'script!foundation-sites/dist/foundation.min.js',
        './dist/app.js' ],
        react: ['react', 'react-dom']
    },
     externals: {
        jquery: 'jQuery'
    },
    plugins: [
        new webpack.ProvidePlugin({
            '$': 'jquery',
            'jQuery': 'jquery'
        }),
        new CommonsChunkPlugin('react', 'react.bundle.js')
    ],
    output: {
        filename: bundle.js'
        },

    devServer: {

        inline: true,
        contentBase: './build',
        port: 3000
    },

    module: {
        loaders: [
          {
            loader: 'babel-loader',
            query: {
              presets: ['react', 'es2015']
            },
            test: /\.js?$/,
            exclude: /(node_modules)/
          }
        ]
    }
};

package.json

{
  "name": "boilerplate",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "webpack",
    "start": "webpack-dev-server",
    "test": "karma start"
  },
  "author": "CBM",
  "license": "MIT",
  "dependencies": {
    "react": "^15.3.2",
    "react-dom": "^15.3.2"
  },
  "devDependencies": {
    "babel-core": "^6.16.0",
    "babel-loader": "^6.2.5",
    "babel-preset-es2015": "^6.16.0",
    "babel-preset-react": "^6.16.0",
    "css-loader": "^0.25.0",
    "foundation-sites": "^6.2.3",
    "jquery": "^3.1.1",
    "karma": "^1.3.0",
    "karma-firefox-launcher": "^1.0.0",
    "karma-mocha": "^1.2.0",
    "karma-mocha-reporter": "^2.2.0",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-webpack": "^1.8.0",
    "mocha": "^3.1.0",
    "react-router": "^2.8.1",
    "script-loader": "^0.7.0",
    "style-loader": "^0.13.1",
    "webpack": "^1.13.2",
    "webpack-dev-server": "^1.16.1"
  }
}

babel.rc

{
    "presets": ["es2015", "react"]
}

Answer №1

Provide a specific output for each item:

itemList: {
    bootstrap: ['script!bootstrap/dist/bootstrap.min.js', 'script!jquery/dist/jquery.min.js' ],
    main: './dist/main.js',
    reactComponents: ['react', 'react-dom']
},
outputFiles: {
    filename: '[name].bundle.js'
}

To include jquery and bootstrap libraries directly in the HTML, exclude them from the entries. Reference: Webpack - Multiple Entry Points Documentation

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

What could be the reason behind the index not getting properly set for the array that was cloned afterward?

I need assistance with a code snippet that clones an array, resets the index (0, 1, 2 ...), and stores it in a variable named buildingsPayload: console.log('1:', this.buildings) const buildingsPayload = this.buildings.map((building, index) => ...

Designing a login system with MEAN stack architecture?

I am currently in the process of building a web application using the MEAN stack (MongoDB, Express, AngularJS, and node.js). Specifically, I am working on implementing a login system and securing certain routes in my Angular app so that they are only acces ...

Setting a single value for several identifiers within a JSON object

I'm new to JSON and I'm curious if it's possible to have a name/value pair with multiple names. Essentially, I want to be able to search for either name and retrieve the same value without having to update the value in two different places. ...

Looking for a way to extract Regular Expressions from an IgGrid cell in Infragistics?

Is it possible to apply a regular expression to a igTextEditor within an igGrid Updating? I attempted to utilize the validate option, but it was unsuccessful. $("#schedulerTable").igGrid({ columns: $scope.schedulerColumns, widt ...

What could be causing the malfunction of my href directory in my ReactJS project?

When I click the "Join Now" button, I am attempting to navigate to a specific file but it does not appear to be functioning as expected. In the image below, you can see that on line 9 there is an href for '/auth/login', however, when I click the ...

Broadcasting events across the entire system

I'm trying to accomplish something specific in Angular2 - emitting a custom event globally and having multiple components listen to it, not just following the parent-child pattern. Within my event source component, I have: export class EventSourceCo ...

Error message: Unexpected character found at the beginning of JSON data - REST API using node.js and Express

Recently, I have embarked on the journey of learning REST API with node and express. My main goal is to achieve file read and write operations using APIs. However, a frustrating error arises when attempting to hit the API through Postman. Strangely enough, ...

Creating a visually appealing stacked bar chart using data pulled from a database with High Charts

I am a beginner with Highcharts and I am looking for assistance on creating a stacked column chart using data from a database. I have searched through various online samples, but all of them use static data. Can anyone provide guidance on how to achieve th ...

Tips for showing an Inline Autocomplete element

Is there a way to display the Autocomplete component inline alongside other React MUI components? Referring to the example of countries from the documentation: https://codesandbox.io/s/countryselect-material-demo-2g0jeu?fontsize=14&hidenavigation=1&a ...

What is causing the issue where search query parameters are not recognizing the initially selected option?

Hey, I'm having an issue with searchParams. The problem is that when I apply filters like "Breakfast, Lunch, Dinner", the first chosen option isn't showing up in the URL bar. For example, if I choose breakfast nothing happens, but if I choose lun ...

Creating JSON with PHP: Ensuring consistent keys in JSON output derived from PHP arrays

Is there a method to convert a PHP array (or any other similar PHP object) into JSON while maintaining identical keys for a JSON array? For example: {"categories" : [ {"key": "data1"}, {"key": "data2"}, {"key": "data3" } ] } It is worth noting that the ...

Generating a JSON object on the fly in a React Native application

There have been similar questions asked in the past like this & this. After looking at those SO questions, I came up with this code. As a newcomer to React Native and Javascript, I am facing two issues. 1. I'm trying to structure my data like this ...

Exploring tailored markup features in Next.js version 13

I am trying to optimize my website for social media sharing on platforms like WhatsApp. I have been experimenting with different methods to set custom markup in Next.js 13, but haven't achieved the desired outcome yet. Your help and insight are greatl ...

Stop the Sidebar from showing up on certain pages with Next.js

Currently, I am facing a small issue with my application. The problem lies in the sidebar that appears on my login.jsx page when I specifically do not want it there. However, I would like it to appear on all other pages except for this one. Is there a cond ...

Issue with resolving the '@/theme' module while using Material UI with Nextjs

As a newcomer to MUI, I am facing an issue with the material-ui-nextjs app router example. After setting up the project, I encountered an error when trying to import the theme module - "Module not found: Can't resolve '@/theme'". Below are s ...

Node.js console and endpoint are returning an object, but the JSON object cannot be fetched

Currently, I am working on a project for an online course where I am utilizing an NLP sentiment analysis API. Although I have made significant progress, I seem to be stuck at the final step. When I send the URL for analysis via the API call, I can see the ...

Comparison between SQL and jQuery regarding String Length Problems

I am facing an issue where the length of a string calculated using Sql Server (LEN) and jQuery ($(this).val().length) is different. The content of the string in question is as follows: 'Project Noida Ka-Rate Gr. Noida Ka AJNARA AMBROSIA-Sec. 118 ...

What steps do I need to take in order to transform my react js and vite app into a progressive web application (PWA

After doing some research, I'm still struggling to properly configure my reactjs website into a PWA I've placed a workbox-config.js file in the project root, and a manifest.json file at the top of my App.js, but I feel like there's more tha ...

Ways to access the scrollTop attribute during active user scrolling

I've been working on a website that utilizes AJAX to keep a chat section updated in real-time. One issue I encountered was ensuring the chat automatically scrolled to the bottom when a user sent a message, but remained scrollable while new messages we ...

The functionality of JQuery's `.on("click"... is sporadically functioning

I have a code block that dynamically generates elements and includes event handling. However, the event handling sometimes works and other times it doesn't. I'm not sure how to debug this issue. Can someone help me figure out what might be causin ...