简体   繁体   English

如何将 build react app (js,css) 添加到 Laravel 后端服务器中

[英]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.jsreact.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.

相关问题 如何将自己的css和js文件添加到Angular 2 App的构建中? - How to add own css and js files to the build of Angular 2 App? 如何将表单数据从 React 发送到 Node JS 后端服务器 - How to send form data from React to the Node JS back end server 本地 React 构建有效,但服务器上的错误 404 构建 js css 文件。 如何让包裹正确构建路径? - Local React build works but Error 404 on the server build js css files. How to get parcel to build the paths correctly? 如何在反应js中使用css在末尾显示2行省略号? - How to display 2 lines with ellipsis at the end with css in react js? 如何使用后端 Node.js Express-Sessions 对 React 前端进行身份验证? - How to authentication React Front End with back-end Node.js Express-Sessions? 我可以在哪里将 JWT 令牌存储在 React js 中,以验证应用程序后端的各种路由? - Where I can store JWT token in React js for authenticate the various routes on back end of app? 如何使用Material-ui为React Next应用添加CSS服务器端渲染 - How to add CSS server side render for React Next app with Material-ui 如何使用node.js后端服务器与前端和mongolab数据库进行交互? - How to use a node.js back-end server to interact with the front-end and a mongolab database? Laravel 6 CSS JS 未加载到服务器上 - Laravel 6 CSS JS not loading on server 如何使用react js添加平滑滚动返回顶部按钮? - How to Add Smooth Scrolling Back To Top Button using react js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM