[英]How to add build react app (js,css) in to the laravel back end server
I have a front end app (React js) and Back end (Laravel) server.我有一个前端应用程序(React js)和后端(Laravel)服务器。 I build the front end(Reactapp) using npm run build
.now I got the build folder ( -->static folder-->css
, js
, media folder
).我使用npm run build
构建前端(Reactapp)。现在我得到了构建文件夹( -->static folder-->css
, js
, media folder
)。
I need to add these static folders ( CSS, js, media
) to the back end ( Laravel server
) and configure.我需要将这些静态文件夹( CSS, js, media
)添加到后端( Laravel server
)并进行配置。 It means when I start PHP artisan serve
my frond-end react app should be rendered.这意味着当我启动PHP artisan serve
我的前端 React 应用程序应该被渲染。
how can I add static folders to the back end and configure?如何将静态文件夹添加到后端并进行配置?
By default laravel comes with vue.js
.默认情况下,laravel 带有vue.js
。 To use react.js
in laravel app, You shoudl change from vue.js
to react.js
by using the following command .要使用react.js
在laravel应用程序,您shoudl从改变vue.js
到react.js
使用下面的命令。
php artisan preset react
Then install npm
in your laravel directory by using ,然后npm
在 Laravel 目录中安装npm
,
npm install
Push your react.js
code into resources/js/
folder.将您的react.js
代码推送到resources/js/
文件夹。 Change the app.js
contents also.还要更改app.js
内容。 For more info, follow the tutorial .有关更多信息,请按照教程进行操作。 laravel-react-tutorial laravel-react-教程
Just copy your static folder from your build file and paste it to Laravel Pubilc Dir.只需从构建文件中复制静态文件夹并将其粘贴到 Laravel 公共目录。
Now we have to find the server.php and change the initial rendering page index.php as index.html.现在我们必须找到 server.php 并将初始渲染页面 index.php 更改为 index.html。
require_once __DIR__.'/public/index.html';
That's all your front end app(React Js) configure with back end (Laravel)这就是您的前端应用程序(React Js)与后端(Laravel)配置的所有内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.