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 ?)
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I highly recommend you could use "create-react-app" as your first step in React world which link is here. The package includes all you need including the function like nodemon for node and you don't need to worry about the environmental setting.
Enjoy it.
回答2:
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",
// ...
}
// ...
}
Now, using npm start
and then changing src files I can see changes in the browser.
Please here https://webpack.js.org/configuration/watch/ for more options.