简体   繁体   English

我需要我的 ReactJS 应用程序在没有服务器的情况下离线工作

[英]I need my ReactJS app working offline without server

I have simple one page html/js/ReactJS app which is used with the help of such scripts added to index.html.我有一个简单的一页 html/js/ReactJS 应用程序,它在添加到 index.html 的此类脚本的帮助下使用。 It is running without any server, because client needs it to be used only on his computer:它在没有任何服务器的情况下运行,因为客户端只需要在他的计算机上使用它:

  <script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
  <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"</script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.25.0/babel.min.js"></script>

How can I make this app working offline?我怎样才能让这个应用离线工作? I can use Node Server, but when application is downloaded by client it needs to be opened using the only index.html file.我可以使用节点服务器,但是当客户端下载应用程序时,它需要使用唯一的index.html文件打开。

Just download the three files above:只需下载上面的三个文件:

You can do this by going to the src links in your script tags above, right-click the webpage, click Save As , choose file type as JavaScript and then replace the above src links in your index.html to those downloaded files.您可以通过转到上面脚本标签中的 src 链接,右键单击网页,单击Save As ,选择文件类型为 JavaScript,然后将 index.html 中的上述 src 链接替换为那些下载的文件。

You can create a special folder for the site and within the folder, you can paste a copy of your index.html file as well as a js folder and keep the above three downloaded JavaScript files in that js folder.您可以为站点创建一个特殊文件夹,在该文件夹中,您可以粘贴 index.html 文件的副本以及一个 js 文件夹,并将上述三个下载的 JavaScript 文件保存在该 js 文件夹中。

You can now simply replace the src link in the above three scripts tags like this:您现在可以简单地替换上述三个脚本标签中的 src 链接,如下所示:

<script src="js/react.production.min.js" />
<script src="js/react-dom.production.min.js" />
<script src="js/babel.min.js" />

However, this only works if the client is just viewing the site.但是,这仅在客户端只是查看站点时才有效。 If the client wants to say, edit the files and want something like hot reload , they will need to set up a server for that.如果客户端想说,编辑文件并想要诸如hot reload类的东西,他们将需要为此设置一个服务器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的 Reactjs 应用程序中是否需要全局 state? - Do I need a global state in my Reactjs app? 我是否需要创建本机应用程序才能离线使用传单地图 - Do I need to create native app to use leaflet map offline React.js-我想使用一些json服务器模拟数据来测试我的登录应用 - Reactjs - I want to use some json-server mocked data to test my login app 我无法在Heroku中运行我的ReactJS应用 - I cant run my ReactJS app in Heroku 如果我包括dom4 polyfill,ReactJs应用程序会以任何方式受益吗? 我需要dom4和ReactJs吗? - Will ReactJs app benefit in any way if I will include dom4 polyfill? do i need dom4 with ReactJs? 我需要帮助,无需使用表单即可使用Ajax,PHP和mySQL将信息发送到服务器 - I need help sending information to my server using Ajax, PHP, and mySQL without using a form 我正在尝试在我的反应应用程序中添加图标,但此方法不起作用需要帮助和指导 - I am trying to add icons in my react app but this method not working Need help and guidance 如何在不严重修改现有应用程序的情况下在服务器上呈现我的反应组件? - How Can I render my react components on the server without heavily modifying my existing app? Mobx Reactjs对我不起作用(我无法注入我的商店) - Mobx Reactjs is not working for me(I can't inject my store) 如何让网站显示在我的 reactjs 应用程序的正文中? - How do I get a website to display in the body of my reactjs app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM