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.
-
2Possible duplicate of use create-react-app with php indexGuilherme de Jesus Santos– Guilherme de Jesus Santos2018-09-17 16:45:58 +00:00Commented 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?PlayMa256– PlayMa2562018-09-17 16:53:50 +00:00Commented Sep 17, 2018 at 16:53
Add a comment
|
2 Answers
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');
Comments
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
Diego Santa Cruz Mendezú
Raise the server, but do not read the php code, I'm testing with webpack-php-loader
PlayMa256
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.