This project sets up a development server using Webpack and PHP. It ensures that the PHP server runs concurrently with the Webpack development server, allowing you to develop and test PHP applications seamlessly.
-
Clone the repository:
git clone git@github.com:amenophis1er/webpack-php-proxy-server.git cd webpack-php-proxy-server
-
Install dependencies:
npm install
To set up the development server, you need to modify your Webpack configuration to include the setupDevServer
function.
-
Create or modify your Webpack configuration file:
// webpack.config.js const { setupDevServer } = require('webpack-php-proxy-server'); module.exports = async function (env, argv) { const phpServerDir = 'examples'; // Change to your PHP server directory const apiPrefix = 'api'; // Change to your desired API prefix const config = { // Your existing Webpack configuration }; await setupDevServer(config, { port: 8080, // Optional, specify a port for Webpack dev server phpServerDir, apiPrefix, }); return config; };
-
Run the development server:
npm start
This will start both the Webpack development server and the PHP server.
This project includes tests for the server setup functions using Jest. To run the tests, follow these steps:
-
Install testing dependencies:
npm install --save-dev jest
-
Run the tests:
npm test
The following test cases are included:
-
Testing the
getAvailablePort
function:const { getAvailablePort } = require('webpack-php-proxy-server'); test('finds an available port', async () => { const port = await getAvailablePort(8000, 8005); expect(port).toBeGreaterThanOrEqual(8000); expect(port).toBeLessThanOrEqual(8005); });
The main configuration options for setupDevServer
are:
-
port
: (Optional) Port number for the Webpack development server. If not provided, an available port will be used. -
phpServerDir
: Directory to serve PHP files from. -
apiPrefix
: (Optional) Prefix for API routes. Defaults toapi
.
This project is licensed under the MIT License. See the LICENSE file for details.