为什么我需要一台带有create-react-app的服务器 [英] Why do I need a server with create-react-app
本文介绍了为什么我需要一台带有create-react-app的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我最近用create-react-app创建了一个网站.由于这不是Web应用程序,为什么我需要服务器才能查看它?我试图在build文件夹中打开索引文件,但是除非从服务器提供它,否则它将无法正常工作.
I recently created a website with create-react-app. Since this is not a web app, why do I need a server to see it? I tried to open the index file in build folder but it doesn't work unless I'm serving it from a server.
推荐答案
您可以在 package.json
文件中设置首页根网址,例如
You can set the homepage root url in the package.json
file e.g.
{
...,
"homepage":"file:///<path to build directory"
}
npm运行构建
npm run build
现在,这将在没有服务器的情况下从文件系统中找到构建目录中的静态内容.
This will now find the static content in the build directory from the file system without a server.
这篇关于为什么我需要一台带有create-react-app的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文