How does webpack-dev-middleware work with the express rendering engine?

after using webpack-dev-middleware , the generated html is in memory,
but the route of express, for example,

//app.js
app.set("views", path.join(__dirname, "views"))

// routes.js
router.get("/home", (req,res) => {
  res.render("home")
})
The

rendering engine is looking for home.html in the views folder, but returns 500because home.html is in memory and express cannot find it.

how does webpack-dev-middleware cooperate with express rendering engine?

Mar.01,2021

replace 'home' with your html string


write to the views folder when developing using the webpack-dev-middleware property writeTodisk, which is fine.
however, it doesn't feel like the optimal solution, so you should modify the in-memory data generated by res.render to read webpack-dev-middleware.

Update: the above method produces a pile of temporary files and is discarded.

< hr >

do not use the webpack-dev-middleware attribute writeTodisk
use html-webpack-harddisk-plugin to only export html, to improve the shortcomings of the above scheme.

Menu