create-react-app build 在 LAMP/XAMPP/WAMP 上部署 [英] create-react-app build deploy on LAMP/XAMPP/WAMP

查看:41
本文介绍了create-react-app build 在 LAMP/XAMPP/WAMP 上部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Apache WAMP/XAMPP 服务器上部署构建?

我有一个用 create-react-app 创建的应用程序,我在这个应用程序上有两个页面

I have an app created with create-react-app and I have two pages on this application

当我执行 yarn startnpm start 时,它工作正常,所有页面都在 URL 导航或按钮点击上正确呈现

When I execute yarn start or npm start it's working fine and all the pages are rendering properly on the URL navigation or button click

我执行了构建命令

npm 运行构建

它在 build 文件夹中生成所有 staticindex.html 文件.

It's generating all the static and index.html files on build folder.

我将此构建文件夹内容移动到 wamp 文件夹的 www 并在 url http://localhost 上执行它只显示主页页.下一页给出 404 not found 错误

I moved this build folder content to www of wamp folder and execute on the url http://localhost its showing only the home page. and the next page gives 404 not found error

但是当我执行 npm 命令的 serve 模块时,它在 http://localhost:5000

But when I am executing the serve module of npm command it's working fine on http://localhost:5000

服务构建

请帮助我如何解决这个问题?

我必须在 wamp 服务器上部署我的应用程序都是静态页面,没有其他 api 内容

I have to deploy my application on wamp server all are static pages there is no rest api contents

推荐答案

默认情况下,您的 React 项目构建为直接部署到服务器的www"(根)文件夹中.因此,您可以将项目 'build' 文件夹的内容复制到 WAMP 'www' 文件夹,然后转到 http://localhost/ 在您的浏览器中.将显示您的项目.

By default, your react project is built to be deployed directly into your server 'www' (root) folder. Hence you may copy the contents of your project 'build' folder to the WAMP 'www' folder and then go to http://localhost/ in your browser. Your project will be displayed.

或者,您可能想要使用 WAMP 根子文件夹,例如'www/反应/'.在这种情况下,将 主页 键添加到您的 package.json 文件中:

Alternatively, you may want to use a WAMP root subfolder, e.g. 'www/react/'. In this case add to your package.json file a homepage key:

"homepage": "http://localhost/react/",

然后再次构建您的项目:

Then build your project again:

npm run build

最后,将项目build"文件夹的内容复制到www/react/".要显示您的项目,请访问 http://localhost/react/

Finally, copy the contents of your project 'build' folder to 'www/react/'. To display your project visit http://localhost/react/

您可以在如何在 Apache Web 服务器上部署 React 应用程序

这篇关于create-react-app build 在 LAMP/XAMPP/WAMP 上部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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