use create-react-app with php index

2020-02-29 20:03发布

问题:

i want to start new react project using great create-react-app tool, but i need to serve app using php to allow me to fetch some dynamic data and configuration and feed it to react before it starts.

how can i config create-react-app to server php ?

php have its own builtin server, so may be we can use it to launch index.php

php -S localhost:8000 ./public/index.php

is there a way to let webpack launch php built-in server and still have all live reload and features that comes with react-create-app ?

回答1:

Use below code:

  1. Open your application folder in command line.
  2. Write below code with your react config file. (E.g: development.config.js)

Code

webpack-dev-server --progress --inline --hot --port 8080 --config reactconfig/development.config.js

OR

npm start