vite-plugin-php 2.0.3 → 3.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +132 -65
- package/dist/index.cjs +3589 -378
- package/dist/index.mjs +3584 -374
- package/package.json +8 -10
package/README.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
<p align="center" style="text-align: center;">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
<img
|
|
3
|
+
src="https://vite-php.nititech.de/assets/vite-php.logo.svg"
|
|
4
|
+
alt="vite-plugin-php logo"
|
|
5
|
+
style="width: 250px; max-width: 100%;" />
|
|
6
6
|
</p>
|
|
7
7
|
|
|
8
8
|
<div style="display: grid; grid-template-columns: max-content max-content; column-gap: 10px;">
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
<a href="https://github.com/donnikitos/vite-plugin-php/blob/master/LICENSE" target="_blank"><img src="https://img.shields.io/github/license/donnikitos/vite-plugin-php?color=blue&style=for-the-badge" alt="License" /></a>
|
|
10
|
+
<div></div>
|
|
11
|
+
<a href="https://www.npmjs.com/package/vite-plugin-php" target="_blank"><img src="https://img.shields.io/npm/dt/vite-plugin-php?style=for-the-badge" alt="NPM" /></a>
|
|
12
|
+
<a href="https://github.com/donnikitos/vite-plugin-php" target="_blank"><img src="https://img.shields.io/github/stars/donnikitos/vite-plugin-php?label=GitHub%20Stars&style=for-the-badge" alt="GitHub Stars" /></a>
|
|
13
|
+
<a href="https://github.com/donnikitos/vite-plugin-php/issues" target="_blank"><img src="https://img.shields.io/github/issues/donnikitos/vite-plugin-php?style=for-the-badge" alt="Issues" /></a>
|
|
14
|
+
<img src="https://img.shields.io/github/last-commit/donnikitos/vite-plugin-php?style=for-the-badge" alt="Last Commit" />
|
|
15
15
|
</div>
|
|
16
16
|
|
|
17
17
|
\
|
|
@@ -28,27 +28,19 @@ export default defineConfig({
|
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
<p align="center" style="text-align: center;">
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
<b>
|
|
32
|
+
<a href="https://www.npmjs.com/package/vite-plugin-php">NPM</a> | <a href="https://vite-php.nititech.de/">Wiki</a> | <a href="https://github.com/donnikitos/vite-plugin-php/discussions">Discussions</a> | <a href="https://github.com/nititech/php-vite-starter">Starter-Repo</a>
|
|
33
|
+
</b>
|
|
34
34
|
</p>
|
|
35
35
|
|
|
36
36
|
## ⚡ Latest changes
|
|
37
37
|
|
|
38
|
-
##### Major Release
|
|
38
|
+
##### Major Release 3.0.0 !!!
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
##### Releases >= 1.0.0
|
|
40
|
+
Plugin now fully utilizes the Vite pipeline to load, transform and HTML-transform files in proper order.\
|
|
41
|
+
⚠️ This might result in breaking changes since code can now be affected by other plugins!
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
| ------- | ---------------------------------------------------------------- |
|
|
47
|
-
| 1.0.71 | Fixed assets prepending for namespaced PHP-files |
|
|
48
|
-
| 1.0.70 | Added include path override for relative PHP imports in dev mode |
|
|
49
|
-
| 1.0.69 | Using new token format to escape PHP in HTML |
|
|
50
|
-
| 1.0.68 | Improved transpiled code evaluation (removed native `eval()`) |
|
|
51
|
-
| ... | ... |
|
|
43
|
+
[See changelog](https://vite-php.nititech.de/changelog).
|
|
52
44
|
|
|
53
45
|
## Write some PHP code in your `index.php`
|
|
54
46
|
|
|
@@ -56,22 +48,22 @@ Including full _PHP error logging_ into console, rewritten code for _better perf
|
|
|
56
48
|
<!-- index.php -->
|
|
57
49
|
<!DOCTYPE html>
|
|
58
50
|
<html lang="en">
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
51
|
+
<head>
|
|
52
|
+
<meta charset="UTF-8" />
|
|
53
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
54
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
55
|
+
</head>
|
|
56
|
+
<body>
|
|
57
|
+
<div id="root">
|
|
58
|
+
<?="Render some text with PHP!"; ?>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<?php if(isset($_GET['show_hello'])): ?>
|
|
62
|
+
Hello world!
|
|
63
|
+
<?php endif; ?>
|
|
64
|
+
|
|
65
|
+
<script src="./src/react-app.tsx" type="module"></script>
|
|
66
|
+
</body>
|
|
75
67
|
</html>
|
|
76
68
|
```
|
|
77
69
|
|
|
@@ -205,6 +197,81 @@ export default defineConfig({
|
|
|
205
197
|
This log will be printed into your console, just like any other message about what is happening in Vite.\
|
|
206
198
|
For more details about the meaning of the error level constants, visit the original [PHP-documentation](https://www.php.net/manual/en/errorfunc.constants.php).
|
|
207
199
|
|
|
200
|
+
#### Altering transformation results
|
|
201
|
+
|
|
202
|
+
With additional Vite-plugins you can now alter the outcome of the [`transformIndexHtml()`](https://vite.dev/guide/api-plugin.html#transformindexhtml) pipeline.\
|
|
203
|
+
You can either apply modifications
|
|
204
|
+
|
|
205
|
+
#### `before` PHP and Vite transforms
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
// vite.config.ts
|
|
209
|
+
...,
|
|
210
|
+
plugins: [
|
|
211
|
+
{
|
|
212
|
+
name: 'pre-transform',
|
|
213
|
+
transformIndexHtml: {
|
|
214
|
+
order: 'pre',
|
|
215
|
+
handler(html, ctx) {
|
|
216
|
+
return html.replace(
|
|
217
|
+
'</body>',
|
|
218
|
+
'<div><?= "Pre PHP transform"; ?></div></body>',
|
|
219
|
+
);
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
usePHP(),
|
|
224
|
+
],
|
|
225
|
+
...
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
This adds a hook to run between loading the PHP code and unescaping PHP fragments, prior to passing everything further to Vite's own HTML transformation magic.
|
|
229
|
+
|
|
230
|
+
#### `after` PHP and Vite transforms
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
// vite.config.ts
|
|
234
|
+
...,
|
|
235
|
+
plugins: [
|
|
236
|
+
usePHP(),
|
|
237
|
+
{
|
|
238
|
+
name: 'post-transform',
|
|
239
|
+
transformIndexHtml(html, ctx) {
|
|
240
|
+
return html.replace(
|
|
241
|
+
'</body>',
|
|
242
|
+
'<div><?= "Post PHP transform"; ?></div></body>',
|
|
243
|
+
);
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
...
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
or
|
|
251
|
+
|
|
252
|
+
```ts
|
|
253
|
+
// vite.config.ts
|
|
254
|
+
...,
|
|
255
|
+
plugins: [
|
|
256
|
+
usePHP(),
|
|
257
|
+
{
|
|
258
|
+
name: 'post-transform',
|
|
259
|
+
transformIndexHtml: {
|
|
260
|
+
order: 'post',
|
|
261
|
+
handler(html, ctx) {
|
|
262
|
+
return html.replace(
|
|
263
|
+
'</body>',
|
|
264
|
+
'<div><?= "Post PHP transform"; ?></div></body>',
|
|
265
|
+
);
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
...
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
This hook runs right after Vite's transformations and unescaping PHP fragments.
|
|
274
|
+
|
|
208
275
|
## Specific oddities
|
|
209
276
|
|
|
210
277
|
#### Inline modules
|
|
@@ -218,7 +285,7 @@ $var = 'foo';
|
|
|
218
285
|
?>
|
|
219
286
|
|
|
220
287
|
<script type="module">
|
|
221
|
-
|
|
288
|
+
console.log('<?=$var; ?>');
|
|
222
289
|
</script>
|
|
223
290
|
```
|
|
224
291
|
|
|
@@ -239,7 +306,7 @@ The plugin won't be able to retain the position of some asset tags like `<script
|
|
|
239
306
|
|
|
240
307
|
```php
|
|
241
308
|
<?php if($some_condition$) { ?>
|
|
242
|
-
|
|
309
|
+
<script src="./src/some_script.js" type="module"></script>
|
|
243
310
|
<?php } ?>
|
|
244
311
|
```
|
|
245
312
|
|
|
@@ -261,26 +328,26 @@ Love open source? Enjoying my project?\
|
|
|
261
328
|
Your support can keep the momentum going! Consider a donation to fuel the creation of more innovative open source software.
|
|
262
329
|
|
|
263
330
|
<table>
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
331
|
+
<tr>
|
|
332
|
+
<td>
|
|
333
|
+
via Ko-Fi
|
|
334
|
+
</td>
|
|
335
|
+
<td>
|
|
336
|
+
Buy me a coffee
|
|
337
|
+
</td>
|
|
338
|
+
<td>
|
|
339
|
+
via PayPal
|
|
340
|
+
</td>
|
|
341
|
+
</tr>
|
|
342
|
+
<tr>
|
|
343
|
+
<td>
|
|
344
|
+
<a href="https://ko-fi.com/Y8Y2ALMG" target="_blank"><img src="https://ko-fi.com/img/githubbutton_sm.svg" alt="Ko-Fi" width="174"></a>
|
|
345
|
+
</td>
|
|
346
|
+
<td>
|
|
347
|
+
<a href="https://www.buymeacoffee.com/donnikitos" target="_blank"><img src="https://nititech.de/donate-buymeacoffee.png" alt="Buy Me A Coffee" width="174"></a>
|
|
348
|
+
</td>
|
|
349
|
+
<td>
|
|
350
|
+
<a href="https://www.paypal.com/donate/?hosted_button_id=EPXZPRTR7JHDW" target="_blank"><img src="https://nititech.de/donate-paypal.png" alt="PayPal" width="174"></a>
|
|
351
|
+
</td>
|
|
352
|
+
</tr>
|
|
286
353
|
</table>
|