【发布时间】:2017-08-21 05:23:57
【问题描述】:
我开始构建一个基于 React、TypeScript 和 Webpack 的小应用程序进行构建。我关注了这篇文章:https://www.typescriptlang.org/docs/handbook/react-&-webpack.html
所有源代码都存储在 GitHub 仓库:https://github.com/aszmyd/webpack-react-typescript-bug
问题:
当我启动 webpack 开发服务器进行本地开发时,它会正确地为 localhost:8080 下的文件提供服务,并根据 webpack 配置正确地注入动态资产。 但是当我更改源文件中的某些内容时,重建会被触发,并且一切似乎都被正确触发了,但是 动态资产没有注入到 index.html。因此,在源 tsx 文件发生任何更改后,我在 localhost:8080 处出现空白屏幕,因为 bundle.js 文件 未注入
所以步骤来reporoduce:
- 克隆我的测试用例仓库:https://github.com/aszmyd/webpack-react-typescript-bug
- 使用
npm install安装依赖 - 运行
npm start - 转到http://localhost:8080
- 更改某些内容,即
src/components/Hello.tsx
初始生成的 index.html 如下所示:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello React!</title>
</head>
<body>
<div id="example"></div>
<script type="text/javascript" src="bundle.js"></script></body>
</html>
在至少 1 次 webpack 开发服务器观看之旅和构建之后:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello React!</title>
</head>
<body>
<div id="example"></div>
</body>
</html>
【问题讨论】:
标签: reactjs typescript webpack webpack-dev-server