3

I have a front end app (React js) and Back end (Laravel) server. I build the front end(Reactapp) using npm run build.now I got the build folder (-->static folder-->css, js,media folder).

I need to add these static folders (CSS, js, media) to the back end (Laravel server) and configure. It means when I start PHP artisan serve my frond-end react app should be rendered.

how can I add static folders to the back end and configure?

2
  • What have you tried so far? Commented Dec 30, 2019 at 11:32
  • @farooq so far I created the react app and got a build file, and I created the Laravel app. Commented Dec 30, 2019 at 11:39

2 Answers 2

2

By default laravel comes with vue.js . To use react.js in laravel app, You shoudl change from vue.js to react.js by using the following command .

php artisan preset react

Then install npm in your laravel directory by using ,

npm install

Push your react.js code into resources/js/ folder. Change the app.js contents also. For more info, follow the tutorial . laravel-react-tutorial

Sign up to request clarification or add additional context in comments.

1 Comment

that's correct. but I don't want to install NPM or adding the package inside the Laravel project. I need how to add a build folder to the Laravel project.
2

enter image description here

Just copy your static folder from your build file and paste it to Laravel Pubilc Dir.

Now we have to find the server.php and change the initial rendering page index.php as index.html.

require_once __DIR__.'/public/index.html';

That's all your front end app(React Js) configure with back end (Laravel)

1 Comment

I did the same thing as u did. I was able to see the frontend page created using React when I access the URL but the response of index.php displays message inside <noscript> tag. From that page for every API only this index.php returns the message inside <noscript> tag. Do you know how to resolve this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.