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

查看:128
本文介绍了create-react-app构建部署在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运行构建

npm run build

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

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

我将此构建文件夹内容移至wamp文件夹的www,并在URL http://localhost上执行,仅显示主页.然后下一页给出404 not found error

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/react/". 在这种情况下,将主页键添加到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 App

You may get more information in How to deploy a React App on Apache web server

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

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