【发布时间】:2018-08-30 12:36:36
【问题描述】:
我正在使用 react 和 webpack 来捆绑文件并将其链接到 index.html,如下所示,
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Demo react</title>
<link rel="shortcut icon" href="filer/DL_Logo.svg" type="image/svg">
</head>
<body>
<h1>Hello this is kinda working...</h1>
<div id="container"></div>
<script src="/dist/bundle.js" type="text/javascript"></script>
<!-- Resource jQuery -->
</body>
</html>
这在我输入标准 url 时起作用,因为 express 会自动找到 index.html 并加载它。但是,如果我尝试将 res.SendFile 用于 index.html 文件,它只会加载 html 内容、H1 标记,但不会显示位于包内的其余反应内容。 这是有效的(自动查找 index.html),
app.use(express.static(__dirname + '/public'));
这不起作用
res.sendFile(__dirname+ "/public/index.html")
【问题讨论】:
标签: javascript node.js reactjs express webpack