vite-plugin-php 1.0.55 → 1.0.61
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 +32 -9
- package/dist/index.cjs +19 -6
- package/dist/index.mjs +19 -6
- package/package.json +39 -40
package/README.md
CHANGED
|
@@ -20,14 +20,15 @@ Check out the [starter repo](https://github.com/nititech/php-vite-starter) for a
|
|
|
20
20
|
|
|
21
21
|
## ⚡ Latest changes
|
|
22
22
|
|
|
23
|
-
| Version | Feature
|
|
24
|
-
| ------- |
|
|
25
|
-
| 1.0.
|
|
26
|
-
| 1.0.
|
|
27
|
-
| 1.0.
|
|
28
|
-
| 1.0.
|
|
29
|
-
| 1.0.
|
|
30
|
-
| 1.0.
|
|
23
|
+
| Version | Feature |
|
|
24
|
+
| ------- | ----------------------------------------------------------------------------------------------------------- |
|
|
25
|
+
| 1.0.60 | Fixed inline module transpiling -> PHP code is being properly inserted into transpiled inline module chunks |
|
|
26
|
+
| 1.0.55 | Fixed pure PHP file processing |
|
|
27
|
+
| 1.0.50 | Using native Rollup pipeline to generate bundle -> proper error messages during build |
|
|
28
|
+
| 1.0.40 | Vite's "HTML Env Replacement" feature in transpiled PHP files |
|
|
29
|
+
| 1.0.30 | Proper PHP header forwarding during development |
|
|
30
|
+
| 1.0.20 | URL rewrite functionality to mimic mod_rewrite & friends |
|
|
31
|
+
| 1.0.11 | Improved Windows support |
|
|
31
32
|
|
|
32
33
|
## Write some PHP code in your `index.php`
|
|
33
34
|
|
|
@@ -130,7 +131,27 @@ usePHP({
|
|
|
130
131
|
|
|
131
132
|
⚠️ **Attention:** If using the rewriteUrl property you will need to exclude (_return undefined_) assets like CSS, JavaScript, Images, etc.., that match your transpiled php file names, on your own!
|
|
132
133
|
|
|
133
|
-
##
|
|
134
|
+
## Specific oddities
|
|
135
|
+
|
|
136
|
+
#### Inline modules
|
|
137
|
+
|
|
138
|
+
⚠️ PHP will work somehow unintuitive in inlined modules.
|
|
139
|
+
E.g. you have a page with some variables:
|
|
140
|
+
|
|
141
|
+
```php
|
|
142
|
+
<?php
|
|
143
|
+
$var = 'foo';
|
|
144
|
+
?>
|
|
145
|
+
|
|
146
|
+
<script type="module">
|
|
147
|
+
console.log('<?=$var; ?>');
|
|
148
|
+
</script>
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
This will not work. `$var` will be undefined in the module since the script is being transpiled into a separate file and included separately.
|
|
152
|
+
Same applies to other server variables like `$_GET`, `$_POST` and so on - they will not have the same value as the main PHP file.
|
|
153
|
+
|
|
154
|
+
#### Dynamically included asset processing
|
|
134
155
|
|
|
135
156
|
Vite won't be able to process PHP-computed styles, scripts or images:
|
|
136
157
|
|
|
@@ -138,6 +159,8 @@ Vite won't be able to process PHP-computed styles, scripts or images:
|
|
|
138
159
|
<script src="./src/<?='dynamic_script_name';?>.js" type="module"></script>
|
|
139
160
|
```
|
|
140
161
|
|
|
162
|
+
## Issues
|
|
163
|
+
|
|
141
164
|
If you encounter any other bugs or need some other features feel free to open an [issue](https://github.com/donnikitos/vite-plugin-php/issues).
|
|
142
165
|
|
|
143
166
|
## Support
|
package/dist/index.cjs
CHANGED
|
@@ -7065,7 +7065,7 @@ function usePHP(cfg = {}) {
|
|
|
7065
7065
|
phpServer.start(viteServer?.config.root);
|
|
7066
7066
|
server.middlewares.use(async (req, res, next) => {
|
|
7067
7067
|
try {
|
|
7068
|
-
if (req.url && !["/@vite", "/@fs"].some(
|
|
7068
|
+
if (req.url && !["/@vite", "/@fs", "/@id/__x00__"].some(
|
|
7069
7069
|
(path) => req.url.startsWith(path)
|
|
7070
7070
|
)) {
|
|
7071
7071
|
const url = new URL(req.url, "http://localhost");
|
|
@@ -7125,9 +7125,9 @@ function usePHP(cfg = {}) {
|
|
|
7125
7125
|
).on("error", reject).end();
|
|
7126
7126
|
});
|
|
7127
7127
|
const out = await server.transformIndexHtml(
|
|
7128
|
-
|
|
7128
|
+
requestUrl,
|
|
7129
7129
|
phpResult.content,
|
|
7130
|
-
|
|
7130
|
+
"/" + entryPathname
|
|
7131
7131
|
);
|
|
7132
7132
|
res.writeHead(phpResult.statusCode || 200, {
|
|
7133
7133
|
...req.headers,
|
|
@@ -7143,7 +7143,7 @@ function usePHP(cfg = {}) {
|
|
|
7143
7143
|
next();
|
|
7144
7144
|
});
|
|
7145
7145
|
},
|
|
7146
|
-
handleHotUpdate({ server, file }) {
|
|
7146
|
+
async handleHotUpdate({ server, file }) {
|
|
7147
7147
|
const entry2 = entries.find(
|
|
7148
7148
|
(entryFile) => require$$0$1.resolve(entryFile) === file
|
|
7149
7149
|
);
|
|
@@ -7153,9 +7153,11 @@ function usePHP(cfg = {}) {
|
|
|
7153
7153
|
inputFile: entry2,
|
|
7154
7154
|
config
|
|
7155
7155
|
}).write(outputFile);
|
|
7156
|
+
server.moduleGraph.invalidateAll();
|
|
7157
|
+
}
|
|
7158
|
+
if (entry2 || !file.startsWith(require$$0$1.resolve(tempDir)) && file.includes(".php")) {
|
|
7156
7159
|
server.ws.send({
|
|
7157
|
-
type: "full-reload"
|
|
7158
|
-
path: "*"
|
|
7160
|
+
type: "full-reload"
|
|
7159
7161
|
});
|
|
7160
7162
|
}
|
|
7161
7163
|
}
|
|
@@ -7167,6 +7169,7 @@ function usePHP(cfg = {}) {
|
|
|
7167
7169
|
resolveId(source, importer, options) {
|
|
7168
7170
|
if (entries.includes(source)) {
|
|
7169
7171
|
return {
|
|
7172
|
+
// Rename ids because Vite transforms only .html files: https://github.com/vitejs/vite/blob/0cde495ebeb48bcfb5961784a30bfaed997790a0/packages/vite/src/node/plugins/html.ts#L330
|
|
7170
7173
|
id: `${source}.html`,
|
|
7171
7174
|
resolvedBy: "vite-plugin-php",
|
|
7172
7175
|
meta: {
|
|
@@ -7203,6 +7206,16 @@ function usePHP(cfg = {}) {
|
|
|
7203
7206
|
phpCodes: meta.phpCodes
|
|
7204
7207
|
});
|
|
7205
7208
|
}
|
|
7209
|
+
} else if (item.type === "chunk" && item.facadeModuleId) {
|
|
7210
|
+
const meta = this.getModuleInfo(
|
|
7211
|
+
item.facadeModuleId
|
|
7212
|
+
)?.meta;
|
|
7213
|
+
if (meta?.phpCodes) {
|
|
7214
|
+
item.code = unescapePHP({
|
|
7215
|
+
escapedCode: item.code,
|
|
7216
|
+
phpCodes: meta.phpCodes
|
|
7217
|
+
});
|
|
7218
|
+
}
|
|
7206
7219
|
}
|
|
7207
7220
|
});
|
|
7208
7221
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -7051,7 +7051,7 @@ function usePHP(cfg = {}) {
|
|
|
7051
7051
|
phpServer.start(viteServer?.config.root);
|
|
7052
7052
|
server.middlewares.use(async (req, res, next) => {
|
|
7053
7053
|
try {
|
|
7054
|
-
if (req.url && !["/@vite", "/@fs"].some(
|
|
7054
|
+
if (req.url && !["/@vite", "/@fs", "/@id/__x00__"].some(
|
|
7055
7055
|
(path) => req.url.startsWith(path)
|
|
7056
7056
|
)) {
|
|
7057
7057
|
const url = new URL(req.url, "http://localhost");
|
|
@@ -7111,9 +7111,9 @@ function usePHP(cfg = {}) {
|
|
|
7111
7111
|
).on("error", reject).end();
|
|
7112
7112
|
});
|
|
7113
7113
|
const out = await server.transformIndexHtml(
|
|
7114
|
-
|
|
7114
|
+
requestUrl,
|
|
7115
7115
|
phpResult.content,
|
|
7116
|
-
|
|
7116
|
+
"/" + entryPathname
|
|
7117
7117
|
);
|
|
7118
7118
|
res.writeHead(phpResult.statusCode || 200, {
|
|
7119
7119
|
...req.headers,
|
|
@@ -7129,7 +7129,7 @@ function usePHP(cfg = {}) {
|
|
|
7129
7129
|
next();
|
|
7130
7130
|
});
|
|
7131
7131
|
},
|
|
7132
|
-
handleHotUpdate({ server, file }) {
|
|
7132
|
+
async handleHotUpdate({ server, file }) {
|
|
7133
7133
|
const entry2 = entries.find(
|
|
7134
7134
|
(entryFile) => resolve(entryFile) === file
|
|
7135
7135
|
);
|
|
@@ -7139,9 +7139,11 @@ function usePHP(cfg = {}) {
|
|
|
7139
7139
|
inputFile: entry2,
|
|
7140
7140
|
config
|
|
7141
7141
|
}).write(outputFile);
|
|
7142
|
+
server.moduleGraph.invalidateAll();
|
|
7143
|
+
}
|
|
7144
|
+
if (entry2 || !file.startsWith(resolve(tempDir)) && file.includes(".php")) {
|
|
7142
7145
|
server.ws.send({
|
|
7143
|
-
type: "full-reload"
|
|
7144
|
-
path: "*"
|
|
7146
|
+
type: "full-reload"
|
|
7145
7147
|
});
|
|
7146
7148
|
}
|
|
7147
7149
|
}
|
|
@@ -7153,6 +7155,7 @@ function usePHP(cfg = {}) {
|
|
|
7153
7155
|
resolveId(source, importer, options) {
|
|
7154
7156
|
if (entries.includes(source)) {
|
|
7155
7157
|
return {
|
|
7158
|
+
// Rename ids because Vite transforms only .html files: https://github.com/vitejs/vite/blob/0cde495ebeb48bcfb5961784a30bfaed997790a0/packages/vite/src/node/plugins/html.ts#L330
|
|
7156
7159
|
id: `${source}.html`,
|
|
7157
7160
|
resolvedBy: "vite-plugin-php",
|
|
7158
7161
|
meta: {
|
|
@@ -7189,6 +7192,16 @@ function usePHP(cfg = {}) {
|
|
|
7189
7192
|
phpCodes: meta.phpCodes
|
|
7190
7193
|
});
|
|
7191
7194
|
}
|
|
7195
|
+
} else if (item.type === "chunk" && item.facadeModuleId) {
|
|
7196
|
+
const meta = this.getModuleInfo(
|
|
7197
|
+
item.facadeModuleId
|
|
7198
|
+
)?.meta;
|
|
7199
|
+
if (meta?.phpCodes) {
|
|
7200
|
+
item.code = unescapePHP({
|
|
7201
|
+
escapedCode: item.code,
|
|
7202
|
+
phpCodes: meta.phpCodes
|
|
7203
|
+
});
|
|
7204
|
+
}
|
|
7192
7205
|
}
|
|
7193
7206
|
});
|
|
7194
7207
|
}
|
package/package.json
CHANGED
|
@@ -1,43 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-php",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Process PHP-files with the speed and tools of Vite",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"vite",
|
|
7
|
-
"vite-plugin",
|
|
8
|
-
"load php",
|
|
9
|
-
"use php",
|
|
10
|
-
"vite php",
|
|
11
|
-
"compile php",
|
|
12
|
-
"php",
|
|
13
|
-
"php-loader",
|
|
14
|
-
"php-compiler",
|
|
15
|
-
"php processing",
|
|
16
|
-
"php transpilation",
|
|
17
|
-
"php-vite",
|
|
18
|
-
"vite-php",
|
|
19
|
-
"loader",
|
|
20
|
-
"url rewrite",
|
|
21
|
-
"url router",
|
|
22
|
-
"mod_rewrite"
|
|
23
|
-
],
|
|
3
|
+
"version": "1.0.61",
|
|
24
4
|
"author": "Nikita 'donnikitos' Nitichevski <me@donnikitos.com> (https://donnikitos.com/)",
|
|
25
|
-
"license": "MIT",
|
|
26
|
-
"bugs": {
|
|
27
|
-
"url": "https://github.com/donnikitos/vite-plugin-php/issues"
|
|
28
|
-
},
|
|
29
|
-
"homepage": "https://github.com/donnikitos/vite-plugin-php#readme",
|
|
30
5
|
"repository": {
|
|
31
6
|
"type": "git",
|
|
32
7
|
"url": "git+ssh://git@github.com/donnikitos/vite-plugin-php.git"
|
|
33
8
|
},
|
|
34
|
-
"files": [
|
|
35
|
-
"dist"
|
|
36
|
-
],
|
|
37
|
-
"type": "module",
|
|
38
9
|
"main": "./dist/index.mjs",
|
|
39
10
|
"module": "./dist/index.mjs",
|
|
40
|
-
"
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@types/node": "^22.4.0",
|
|
13
|
+
"fast-glob": "^3.3.2",
|
|
14
|
+
"picocolors": "^1.0.1",
|
|
15
|
+
"typescript": "^5.5.4",
|
|
16
|
+
"unbuild": "^2.0.0",
|
|
17
|
+
"vite": "^5.4.1"
|
|
18
|
+
},
|
|
41
19
|
"exports": {
|
|
42
20
|
".": {
|
|
43
21
|
"require": {
|
|
@@ -52,17 +30,38 @@
|
|
|
52
30
|
"default": "./dist/index.mjs"
|
|
53
31
|
}
|
|
54
32
|
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/donnikitos/vite-plugin-php/issues"
|
|
35
|
+
},
|
|
36
|
+
"description": "Process PHP-files with the speed and tools of Vite",
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
40
|
+
"homepage": "https://github.com/donnikitos/vite-plugin-php#readme",
|
|
41
|
+
"keywords": [
|
|
42
|
+
"vite",
|
|
43
|
+
"vite-plugin",
|
|
44
|
+
"load php",
|
|
45
|
+
"use php",
|
|
46
|
+
"vite php",
|
|
47
|
+
"compile php",
|
|
48
|
+
"php",
|
|
49
|
+
"php-loader",
|
|
50
|
+
"php-compiler",
|
|
51
|
+
"php processing",
|
|
52
|
+
"php transpilation",
|
|
53
|
+
"php-vite",
|
|
54
|
+
"vite-php",
|
|
55
|
+
"loader",
|
|
56
|
+
"url rewrite",
|
|
57
|
+
"url router",
|
|
58
|
+
"mod_rewrite"
|
|
59
|
+
],
|
|
60
|
+
"license": "MIT",
|
|
55
61
|
"scripts": {
|
|
56
62
|
"build": "npx unbuild",
|
|
57
63
|
"prepack": "npm run build"
|
|
58
64
|
},
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"@types/node": "^20.14.11",
|
|
62
|
-
"fast-glob": "^3.3.2",
|
|
63
|
-
"picocolors": "^1.0.1",
|
|
64
|
-
"typescript": "^5.5.3",
|
|
65
|
-
"unbuild": "^2.0.0",
|
|
66
|
-
"vite": "^5.3.4"
|
|
67
|
-
}
|
|
65
|
+
"type": "module",
|
|
66
|
+
"types": "./dist/index.d.ts"
|
|
68
67
|
}
|