0

Good day,

I set up Webpack to create an optimized build of my React application to /dist/ with webpack --mode production --config webpack.config.production.js , which automatically inserts the correct initial script into the head of index.html (webpack.config.production.js, index.html). This works using my Rust back-end to serve the production-built files. However, my script that utilizes webpack serve --mode development --config webpack.config.js to enable hot-reloading does not insert the named script into the HTML file, and thus fails to load (webpack.config.js).

I have spent the past hour and a half trying everything I could find to fix this to no avail, and I would greatly appreciate any assistance. Further, if there is a way to utilize my Rust backend with hot-reloading that would be a superior solution :).

0

1 Answer 1

1

@Robert was on the right track, the problem is that you have two different publicPaths in your webpack.config.js:

For example, your output's publicPath is /:

...
output: {
  filename: "static/[name].[fullhash].js",
  path: path.resolve(__dirname, "dist"),
  publicPath: "/",
},

while your devServer's output is http://localhost:3000/dist/:

...
devServer: {
  contentBase: path.join(__dirname, "public/"),
  port: 3000,
  publicPath: "http://localhost:3000/dist/",
  open: true,
},
...

Instead, they should be the same path -- in this case, they should be / (alternatively, you can remove the publicPath property from devServer and it'll work as well):

devServer: {
  contentBase: path.join(__dirname, "public/"),
  port: 3000,
  // publicPath: "/",
  open: true,
},
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.