-3

Execute npm run eject and rename index.php to index.html, but it does not work. I need to include a class inside index.php to use a function that converts data encrypt to send toward React.

2
  • 2
    Possible duplicate of use create-react-app with php index Commented Sep 17, 2018 at 16:45
  • Are you using any php server to serve that index.php file? Did you rename index after running build? Commented Sep 17, 2018 at 16:53

2 Answers 2

1

Add an .htaccess and an additional index.php file to the /public directory of the app. Load index.php with apache, then require create-react-app's index.html file from PHP.

.htaccess

FallbackResource /index.php

index.php

<?php

// PHP logic here

require_once($_SERVER['DOCUMENT_ROOT'] . '/index.html');
Sign up to request clarification or add additional context in comments.

Comments

-1

I found a solution,

First, execute:

npm run eject

then, change the code in paths.js to:

appHtml: resolveApp('public/index.php')

and webpack.config.dev.js (agree |php):

exclude: [/\.(js|jsx|mjs|php)$/, /\.html$/, /\.json$/]

after:

npm start

this works well

2 Comments

Raise the server, but do not read the php code, I'm testing with webpack-php-loader
Those things won't work. You need a proper php server to run that, i.e: apache, nginx or something like that with php active. Webpack won't solve that problem for you. You'll have to build your project and then copy to where those servers can read your file.

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.