Nodemon没有在React-Express-Node App中刷新浏览器 [英] Nodemon not refreshing browser in React-Express-Node App

查看:256
本文介绍了Nodemon没有在React-Express-Node App中刷新浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的工作区中安装了 nodemon 本地,但即使在更改后它在终端中重新启动,它也不会刷新浏览器页面。我每次都要手动刷新它。

I have installed nodemon locally in my workspace, but even though it restarts in the terminal after changes are made, it does not refresh the browser page. I have to manually refresh it each time.

我在环境中运行了Express,Node,React和Webpack。

I've got Express, Node, React and Webpack running in the environment.

这就是我的设置的样子 -

This is how my setup looks like -

我的 package.json 启动 server.js -

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon server.js"
  },

server.js 是 -

var express = require('express');


     var app = express();
        app.use(express.static('public'));
        app.listen(3000, function () {
            console.log("Express server is up on port 3000");
        });

webpack配置文件中的入口点是 -

The entry point in the webpack config file is -

module.exports = {
    entry: './public/scripts/app.jsx',
    output: {
        path: __dirname,
        filename: './public/scripts/bundle.js'
    }

我该怎么办才能修复它?

What should I do to fix it?

更新 -

我做了视频来描述情况,如果有帮助的话。

I made a video to describe the situation, if it helps.

推荐答案

nodemon仅用于在服务器代码更改时重新启动服务器。它没有在浏览器中重新加载页面的功能。如果您想要自动浏览器重新加载,您可以运行除了nodemon之外的webpack dev服务器。当您的客户端代码发生变化时,webpack dev服务器可以在浏览器中重新加载页面,如果您使用其热模块重新加载功能,它甚至可以在浏览器中更新页面而无需重新加载整页。

nodemon is only for restarting the server when your server code changes. It has no functionality to reload your page in the browser. If you want automatic browser reload, you could, for example, run a webpack dev server in addition to your nodemon. webpack dev server is able reload the page in the browser when your client code changes, it can even update the page in the browser without a full page reload, if you use its hot module reloading feature.

这篇关于Nodemon没有在React-Express-Node App中刷新浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆