File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Get started
2+
3+ ### Installation
4+
5+ First, install vite-plugin-php using npm:
6+
7+ ``` bash
8+ npm install vite-plugin-php@latest --save-dev
9+ ```
10+
11+ ### Adjust Vite
12+
13+ To configure Vite to use vite-plugin-php, update your ` vite.config.js ` file as follows:
14+
15+ ``` javascript
16+ import { defineConfig } from ' vite' ;
17+ import usePHP from ' vite-plugin-php' ;
18+
19+ export default defineConfig ({
20+ plugins: [usePHP ()],
21+ });
22+ ```
23+
24+ ℹ️ By default, the plugin attempts to access the system's php binary and uses ` index.php ` as the main entry point.\
25+ You can alos customize the PHP binary path or specify multiple entry points:
26+
27+ ```
28+ usePHP({
29+ binary: '/path/to/php', // Specify your PHP binary path
30+ entry: ['index.php', 'about.php', 'contact.php'], // Multiple entry points
31+ });
32+ ```
33+
34+ ### Use PHP
35+
36+ Instead of the ` index.html ` create an ` index.php ` file in your project root:
37+
38+ ``` php
39+ <!DOCTYPE html>
40+ <html lang =" en" >
41+ <head >
42+ <meta charset =" UTF-8" />
43+ <meta http-equiv =" X-UA-Compatible" content =" IE=edge" />
44+ <meta name =" viewport" content =" width=device-width, initial-scale=1.0" />
45+ <title >Vite PHP Integration</title >
46+ </head >
47+ <body >
48+ <?php echo "Hello, Vite and PHP!"; ?>
49+
50+ <?php if (isset($_GET['show_me'])): ?>
51+ Hello world!
52+ <?php endif; ?>
53+ </body >
54+ </html >
55+ ```
56+
57+ With this setup, ` vite-plugin-php ` processes your ` index.php ` file, including all imported and preprocessed assets supported by Vite and other loaders.
You can’t perform that action at this time.
0 commit comments