Coder Social home page Coder Social logo

不能热更新 about beidou HOT 13 CLOSED

alibaba avatar alibaba commented on May 1, 2024
不能热更新

from beidou.

Comments (13)

wunayou avatar wunayou commented on May 1, 2024

image

from beidou.

wunayou avatar wunayou commented on May 1, 2024

image2

from beidou.

njugray avatar njugray commented on May 1, 2024

@wunayou
你图中修改的部分代码是 纯服务端(server-side) 运行的代码, 无法进行热更新

热更新必须在 客户端(client-side) 代码中生效.

目前还没有专门针对 HMR的示例, 后续会添加.

redux 中, HMR是生效的, 可以先参考下

from beidou.

wunayou avatar wunayou commented on May 1, 2024

thank you 解决了 继续发现其它的坑

from beidou.

wunayou avatar wunayou commented on May 1, 2024

redux 与router为什么没有结合起来

from beidou.

njugray avatar njugray commented on May 1, 2024

结合 Router 的使用方法可以查看 tree/develop/examples/antd-admin 示例, 包含两个服务端路由和多个浏览器端路由

from beidou.

wunayou avatar wunayou commented on May 1, 2024

@njugray 谢谢你的回答 我看一下代码心中有一个问题 现在大部分的同构是不是都是一个页面一个react 页面

因为看到 login与 dashboard分开的react单页

from beidou.

njugray avatar njugray commented on May 1, 2024

login和dashboard是两个页面, 同时dashboard是一个SPA.

现在大部分的同构是不是都是一个页面一个react 页面

每个页面都会有一个 React View, 在这个例子中是两个. 作用相当于传统视图层(jade, jstl, xtemplate), 只是以React方式实现, 保持编码习惯的一致

from beidou.

KingsleyYu avatar KingsleyYu commented on May 1, 2024

项目:beidou/examples/simple

步骤:

  1. npm init
  2. npm start

浏览器地址栏输入:http://127.0.0.1:6001/style

问题:

  1. 未能成功加载到style.css
    image
  2. 未能热更新。看见上面回复是说修改的部分代码是 纯服务端(server-side) 运行的代码, 无法进行热更新
    热更新必须在 客户端(client-side) 代码中生效.
    问题是simple 中的代码哪些算是client-side 的代码?通过__CLIENT__ 判断运行的代码是客户端代码?

@njugray 盼回

from beidou.

njugray avatar njugray commented on May 1, 2024

@KingsleyYu
抱歉回复晚了

本地开发用 npm run dev 启动, npm start 是生产环境模式运行, 本地的webpack插件不会启动的

from beidou.

wind13 avatar wind13 commented on May 1, 2024

我也遇到不能热更新的问题:

  • 已经使用 npm run dev 启动;
  • 修改的也是 client 目录下的 index.jsx 文件;

还发现很奇怪的现象:

  • 继续尝试热更新,修改更多的文字;
  • 之前的修改在刷新后出现,但半秒后又恢复原样,似乎是被覆盖了;
  • 而最新修改的在刷新时也没有出现,似乎是更新有版本或延时?

经查看,细节是这样:

  • 两次修改文字后,请求先得到渲染的 HTML,文字是第一次修改的;
  • 但之后又加载了 React 的脚本,如 login.js ,是 build 目录下之前编译的,再次改变回了最初的样子。

目前不知道怎么解决,当然重新编译、重新启动服务后,都是正常的,但这里就可以看到实际内容是两次加载的,首次的 HTML 虽然快,但后面的脚本还是比较慢的。看到这个现象还有个 Issue #62

from beidou.

wind13 avatar wind13 commented on May 1, 2024

找到一个可能的问题原因:

/config/ 目录下如果有 env 文件,请检查里面设置是 local 还是 prod,这个可能会决定服务器选择哪种启动模式,如果是 local 这个问题就好了。

from beidou.

njugray avatar njugray commented on May 1, 2024

/config/env 不会在本地生成

可能是在本地跑了prod模式引入的, 这个文件会强制指定运行模式, 优先级高于 npm run dev

from beidou.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.