vite-plugin-php 1.0.55 → 1.0.60

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 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.55 | Auto close last PHP tag if not close (usually PHP only files) |
26
- | 1.0.50 | Using native Rollup pipeline to generate bundle -> proper error messages during build |
27
- | 1.0.40 | Vite's "HTML Env Replacement" feature in transpiled PHP files |
28
- | 1.0.30 | Proper PHP header forwarding during development |
29
- | 1.0.20 | URL rewrite functionality to mimic mod_rewrite & friends |
30
- | 1.0.11 | Improved Windows support |
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
- ## Known issues
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
- "/" + entryPathname,
7128
+ requestUrl,
7129
7129
  phpResult.content,
7130
- req.originalUrl
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,9 @@ function usePHP(cfg = {}) {
7153
7153
  inputFile: entry2,
7154
7154
  config
7155
7155
  }).write(outputFile);
7156
+ server.moduleGraph.invalidateAll();
7156
7157
  server.ws.send({
7157
- type: "full-reload",
7158
- path: "*"
7158
+ type: "full-reload"
7159
7159
  });
7160
7160
  }
7161
7161
  }
@@ -7167,6 +7167,7 @@ function usePHP(cfg = {}) {
7167
7167
  resolveId(source, importer, options) {
7168
7168
  if (entries.includes(source)) {
7169
7169
  return {
7170
+ // Rename ids because Vite transforms only .html files: https://github.com/vitejs/vite/blob/0cde495ebeb48bcfb5961784a30bfaed997790a0/packages/vite/src/node/plugins/html.ts#L330
7170
7171
  id: `${source}.html`,
7171
7172
  resolvedBy: "vite-plugin-php",
7172
7173
  meta: {
@@ -7203,6 +7204,16 @@ function usePHP(cfg = {}) {
7203
7204
  phpCodes: meta.phpCodes
7204
7205
  });
7205
7206
  }
7207
+ } else if (item.type === "chunk" && item.facadeModuleId) {
7208
+ const meta = this.getModuleInfo(
7209
+ item.facadeModuleId
7210
+ )?.meta;
7211
+ if (meta?.phpCodes) {
7212
+ item.code = unescapePHP({
7213
+ escapedCode: item.code,
7214
+ phpCodes: meta.phpCodes
7215
+ });
7216
+ }
7206
7217
  }
7207
7218
  });
7208
7219
  }
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
- "/" + entryPathname,
7114
+ requestUrl,
7115
7115
  phpResult.content,
7116
- req.originalUrl
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,9 @@ function usePHP(cfg = {}) {
7139
7139
  inputFile: entry2,
7140
7140
  config
7141
7141
  }).write(outputFile);
7142
+ server.moduleGraph.invalidateAll();
7142
7143
  server.ws.send({
7143
- type: "full-reload",
7144
- path: "*"
7144
+ type: "full-reload"
7145
7145
  });
7146
7146
  }
7147
7147
  }
@@ -7153,6 +7153,7 @@ function usePHP(cfg = {}) {
7153
7153
  resolveId(source, importer, options) {
7154
7154
  if (entries.includes(source)) {
7155
7155
  return {
7156
+ // Rename ids because Vite transforms only .html files: https://github.com/vitejs/vite/blob/0cde495ebeb48bcfb5961784a30bfaed997790a0/packages/vite/src/node/plugins/html.ts#L330
7156
7157
  id: `${source}.html`,
7157
7158
  resolvedBy: "vite-plugin-php",
7158
7159
  meta: {
@@ -7189,6 +7190,16 @@ function usePHP(cfg = {}) {
7189
7190
  phpCodes: meta.phpCodes
7190
7191
  });
7191
7192
  }
7193
+ } else if (item.type === "chunk" && item.facadeModuleId) {
7194
+ const meta = this.getModuleInfo(
7195
+ item.facadeModuleId
7196
+ )?.meta;
7197
+ if (meta?.phpCodes) {
7198
+ item.code = unescapePHP({
7199
+ escapedCode: item.code,
7200
+ phpCodes: meta.phpCodes
7201
+ });
7202
+ }
7192
7203
  }
7193
7204
  });
7194
7205
  }
package/package.json CHANGED
@@ -1,43 +1,21 @@
1
1
  {
2
2
  "name": "vite-plugin-php",
3
- "version": "1.0.55",
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.60",
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
- "types": "./dist/index.d.ts",
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
- "dependencies": {},
60
- "devDependencies": {
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
  }