You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library provides a lightweight [backend integration](https://vitejs.dev/guide/backend-integration.html)
8
-
for your PHP-based MPA, SPA, or PWA based on [Vite](https://vitejs.dev/).
7
+
This library provides a lightweight [backend integration](https://vitejs.dev/guide/backend-integration.html) for your PHP-based MPA, SPA, or PWA based on [Vite](https://vitejs.dev/).
9
8
10
-
It parses the [build manifest](https://vitejs.dev/config/build-options#build-manifest) (the `.vite/manifest.json` file)
11
-
and produces the required `<script>` and `<link>` tags to load (and preload) scripts, CSS files, and other assets.
9
+
It parses the [build manifest](https://vitejs.dev/config/build-options#build-manifest) (the `.vite/manifest.json` file) and produces the required `<script>` and `<link>` tags to load (and preload) scripts, CSS files, and other assets.
10
+
11
+
## PHP 5.6 Compatible Version
12
+
13
+
> ⚠️ This is a customized fork of the original [`mindplay-dk/php-vite`](https://github.com/mindplay-dk/php-vite) package.
14
+
15
+
This version has been adapted to support **PHP 5.6 and above**, making it suitable for legacy projects that are still running on older PHP versions.
16
+
17
+
### Key differences from the original:
18
+
19
+
* Rewritten to remove syntax and language features that require PHP 8.1+
20
+
* Compatible with PHP 5.6, 7.x, and newer
21
+
* Namespaces changed to `Ngekoding\Vite` to distinguish from the original package
22
+
* Test suite migrated to use PHPUnit
23
+
24
+
If you're working on modern PHP (8.1+), you are encouraged to use the original package:
false, // dev mode (true = development, false = production)
41
+
'/path/to/manifest.json', // path to manifest.json
42
+
'/dist/' // public base path
29
43
);
30
44
```
31
45
32
-
The `manifest_path` points to the Vite `manifest.json` file created for the production build.
33
-
34
-
In this example, `dev` is `false`, so we'll be creating tags for the production assets.
46
+
The constructor accepts three parameters:
35
47
36
-
The `base_path` is relative to your public web root - it is the root folder from which Vite's production assets are served, and/or the root folder from which Vite serves assets dynamically in development mode.
48
+
1.`dev` – set to `true` for development mode, or `false` for production mode.
49
+
2.`manifestPath` – points to the Vite `manifest.json` file created for the production build.
50
+
3.`basePath` – is relative to your public web root, it is the root folder from which Vite's production assets are served, and/or the root folder from which Vite serves assets dynamically in development mode.
37
51
38
52
Note that, in development mode (when `dev` is set to `true`) the `manifest.json` file is unused, and not required.
39
53
@@ -83,23 +97,20 @@ For example:
83
97
84
98
The service preloads any statically imported scripts and CSS files by default.
85
99
86
-
In addition, you can configure it to preload other statically imported assets as well -
87
-
for convenience, there are two methods to automatically configure preloading of all
88
-
common image and font asset types:
100
+
In addition, you can configure it to preload other statically imported assets as well - for convenience, there are two methods to automatically configure preloading of all common image and font asset types:
89
101
90
102
```php
91
103
$manifest->preloadImages();
92
104
$manifest->preloadFonts();
93
105
```
94
106
95
-
You can also configure it to preload any other asset types - for example, to configure
96
-
preloading of `.json` assets, you could add the following:
107
+
You can also configure it to preload any other asset types - for example, to configure preloading of `.json` assets, you could add the following:
97
108
98
109
```php
99
110
$manifest->preload(
100
-
ext: "json",
101
-
mime_type: "application/json",
102
-
preload_as: "fetch"
111
+
"json", // file extension (without dot)
112
+
"application/json", // MIME type
113
+
"fetch" // preload `as` attribute
103
114
);
104
115
```
105
116
@@ -110,7 +121,7 @@ Then create your tags as covered in the documentation above.
110
121
For advanced use cases, you can also directly get the URL for an asset published by Vite:
0 commit comments