Hot Reloading in React with Webpack, no need for Express or Webpack-Dev-Server

My current setup involves a client-server architecture using React+Redux with Webpack to bundle the code into a dist folder. The backend is a go server that serves these files, and I am attempting to enable react-hot-reloading within this configuration. The client communicates with the go server via API calls and websockets.

All the resources I've come across regarding hot reloading mention the need for an Express or Webpack-Dev-Server as a prerequisite. For example:

I'm wondering if there is a way to implement hot reloading in my specific configuration without relying on an Express or Webpack-Dev-Server during development. One possible solution I considered was routing the API calls and websockets through Express or Webpack-Dev-Server, but it seems like a bit of overkill.

Answer №1

Two common traps are associated with these issues:
1. Utilizing webpack-dev-server in a production environment.
2. Encountering CORS security breaches when React script bundles are fetched from one server and then attempt to access another server's API.

If all resources, including script bundles and API responses, are obtained by the client from Express, then CORS becomes irrelevant.

To enable Hot Reloading during development, Express should fetch the bundles from webpack-dev-server and deliver them to the client. This practice should be considered standard procedure rather than excessive, as it ultimately saves substantial development time. Lastly, in a production setting, Express should retrieve bundles from disk.

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

Material design UI - Creating a ListItem link that triggers a dialog box opening

As a React beginner, I am working on a dynamic list of employee items within a Card component for a dashboard. My goal is to create a link for each employee that, when clicked, opens a modal dialog for editing on the same page. I'm struggling with ho ...

Find out the keycode of an event in ReactJS when a key is released

Whenever I try to get keyCode on a keyUp event, it always returns 0. Why is this happening? I want to avoid using keypress and similar methods, and I also need to utilize an arrow function: handleKeyPress = (e, type) => { let KeyCode = e.charCode; ...

Reactjs Invariant Violation caused by the npm package (react-loader)

I'm currently attempting to integrate react-loader into my react component. This is the code snippet I'm using: /** @jsx React.DOM */ var Loader = require('react-loader'); var DisplayController = React.createClass({ // etc ...

Having trouble with NextJs router 404 error when refreshing the page on Digital Ocean?

I am currently working with a NextJs project that has been exported as a static site and is being hosted on Digital Ocean's App platform. I am using next/router to handle routing within the application. One issue that I have encountered is when attem ...

Issue: The "props" method is designed to be executed on a single node, but it was found on 2 nodes instead

it('should execute setCampaignDate when clicked', function () { let spySetCampaign = sinon.spy(wrapper.instance(), 'setCampaignDate'); let datePickers = wrapper.find('.campaign-date-tab').dive().find(Datepicker); a ...

Experimenting with a Node.JS server using my React front-end on my local machine

After successfully setting up my node.JS Express server to send JSON data from an API to the front-end, I deployed it on an AWS server. Now, I am focusing on developing the React front end of the project. However, when I try to make requests from localhost ...

Struggling to traverse through intricate layers of nested objects in React and showcasing them without going crazy

Dealing with an API that returns data structured in deeply nested objects has been a challenging task. The goal is to extract specific data from these nested objects and then display them within a React project. Despite numerous attempts, finding a simple ...

Having trouble with pinning the expand column on the far left side of my Material React Table

I am utilizing the Material React Table to display my data in a tree-like structure. My requirement is to pin the expand column (used for collapsing or expanding rows) at the leftmost position, followed by pinning the tasks column. While I have successful ...

The styling of React-Sidenav's main content is lacking

Currently utilizing the following library: https://github.com/trendmicro-frontend/react-sidenav The Sidenav functionality is working well, but I am facing challenges in implementing the main content style. Any idea why the main content is not included in ...

What is the best way to implement an onHover event in material-table?

Currently, I am experimenting with the library material-table and my goal is to add a highlighting effect to the row that I am hovering over. Even after referring to the official documentation, I could only find an example showcasing a color change on cli ...

What is the best way to handle "passive event listeners" in reactjs when using event.preventDefault with an onWheel event?

My current challenge involves attempting to preventDefault within an onWheel event in order to enable users to horizontally scroll on specific elements rather than just vertically. However, whenever I try to use e.preventDefault, I am consistently met with ...

I created a thorough duplicate that successfully addressed an issue with a table

Currently, I am facing an issue with the material-table library as it automatically adds a new element called tableData to my object when I update it using Patch in my code and API. To resolve this problem, I tried implementing both a conventional and cust ...

Attempting to provide images that are dynamically downloaded in real-time using Express Middleware

I'm facing a challenge with express and middleware. My goal is to serve an image from disk, but if it's not there, download it from an external server and then display it. Subsequent requests for the same image should be served from disk. Downlo ...

What causes setInterval to exponentially increase its logging with each re-render?

import { useState } from "react"; function ParentComp(props){ console.log("parent component is rendering"); const [person, setPerson] = useState({ firstName: "First" }); setInterval(() => { setPerson({ firstName: "Second" }); }, 6000); r ...

"Seamless Integration: Exploring Material-UI's Compatibility with Third-Party

Is it possible to seamlessly integrate material-ui components with non-mui components without any compatibility issues? If there are compatibility issues, what are the reasons behind them? ...

What are the essential steps for effectively unit testing a React component?

When it comes to testing a react component, what are the recommended best practices and key elements to focus on? Typically in standard tests, I verify if the correct state and input produce the expected output. However, React components introduce a uniqu ...

Is it possible to dynamically add and remove items using React state?

I am currently working on implementing a dynamic queue of game players in my React state. The goal is to avoid hardcoding the number of players who can participate and achieve this state update using a JS FIFO queue. My objective is to create a player que ...

Tips for creating a dynamic rowspan feature in Ant Design React components

I'm currently working on creating a table with dynamic rowspan in Ant design (data will be dynamic). Here's the data I have: I want to display it like this. Can anyone offer some assistance? [{"col1":"temp1","col2":"1","col3":"x"}, {"col1":"t ...

Accessing React Context globally using the useContext hook

I'm feeling a bit puzzled about how the useContext hook is intended to function in a "global" state context. Let's take a look at my App.js: import React from 'react'; import Login from './Components/auth/Login'; import &apos ...

What is the reason behind being able to assign unidentified properties to a literal object in TypeScript?

type ExpectedType = Array<{ name: number, gender?: string }> function go1(p: ExpectedType) { } function f() { const a = [{name: 1, age: 2}] go1(a) // no error shown go1([{name: 1, age: 2}]) // error displayed ...