I use Webpack to compile my JS which is then loaded via bundle.js
via a template string sent via express.
The only problem is, I can't find information on how to render custom html while also using webpack-dev-middleware
to watch and compile bundle.js
.
My HTML is being sent with the following code:
app.use('*', (req, res) => {
res.send(`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Title</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="main"></div>
<script type="text/javascript">window.__userData=${JSON.stringify(req.user)}</script>
<script src="/bundle.js" type="text/javascript"></script>
</body>
</html>`);
});
So, I have no idea how I can keep/use this while using webpack-dev-middleware
for the bundle.js
, since what I tried to do was just add app.use
as per webpack-dev-middleware
before the above snippet, though it did not work, failing with the error of bundle.js being of the wrong mime type text/html
, thus not executable.
EDIT
The server-side rendering option for webpack-dev-middleware
is experimental and not what I'm looking for, I don't need raw bundle.js
to send with html.