更新时自动重新加载React服务器 [英] Auto reload react server on update
问题描述
我是React的新手.我在使用React Server时遇到一些问题.通过npm start
启动服务器后,如果我在源代码上工作并进行了一些更改,则必须停止服务器并重新启动它,以使该更改在浏览器上可用.是否有使其自动编译并在更新时刷新浏览器的方法? (就像nodemon
代表节点?)
I'm new to React. I'm having some problems with react server. After starting the server by npm start
if I work on the source code and make some changes, I have to stop the server and restart it to make that change available on the browser. Is there anyway to make it auto compile and refresh the browser on update ? (Like nodemon
for node ?)
推荐答案
我遇到了类似(或相同事件)的问题,并且在package.json
文件中通过添加以下标志更改了启动命令:--watch --watch-poll
到webpack-dev-server
:
I had a similar (or event the same) problem and I changed starting command in the package.json
file by adding following flags: --watch --watch-poll
to the webpack-dev-server
:
{
//...
"scripts": {
"start": "webpack-dev-server --env.ENVIRONMENT=development --content-base src/ --mode development --watch --watch-poll",
// ...
}
// ...
}
现在,使用npm start
,然后更改src文件,我可以在浏览器中看到更改.
Now, using npm start
and then changing src files I can see changes in the browser.
请在此处 https://webpack.js.org/configuration/watch/以获得更多选择.
Please here https://webpack.js.org/configuration/watch/ for more options.
这篇关于更新时自动重新加载React服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!