vite-plugin-php 0.9.0
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/LICENSE +21 -0
- package/README.md +72 -0
- package/dist/index.cjs +182 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.mjs +180 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Nikita Nitichevski
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# vite-plugin-php
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/vite-plugin-php) [](https://github.com/donnikitos/vite-plugin-php) [](https://github.com/donnikitos/vite-plugin-php/blob/master/LICENSE)
|
|
4
|
+
 [](https://github.com/donnikitos/vite-plugin-php/issues)
|
|
5
|
+
|
|
6
|
+
Use Vite's speed and tooling to process PHP-files!
|
|
7
|
+
|
|
8
|
+
```js
|
|
9
|
+
// vite.config.js
|
|
10
|
+
import { defineConfig } from 'vite';
|
|
11
|
+
import usePHP from 'vite-plugin-php';
|
|
12
|
+
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
plugins: [usePHP()],
|
|
15
|
+
});
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Write some PHP code in your `index.php`
|
|
19
|
+
|
|
20
|
+
```php
|
|
21
|
+
<!-- index.php -->
|
|
22
|
+
<!DOCTYPE html>
|
|
23
|
+
<html lang="en">
|
|
24
|
+
<head>
|
|
25
|
+
<meta charset="UTF-8" />
|
|
26
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
27
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<?="Render some text with PHP!";?>
|
|
31
|
+
|
|
32
|
+
<?php if(isset($_GET['dont_load'])) { ?>
|
|
33
|
+
<script src="./src/some_script.js" type="module"></script>
|
|
34
|
+
<?php } ?>
|
|
35
|
+
</body>
|
|
36
|
+
</html>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The plugin will serve you the processed `index.php` as usual, including all imported and preprocessed files that are supported by Vite and other loaders.
|
|
40
|
+
|
|
41
|
+
## Configuration
|
|
42
|
+
|
|
43
|
+
By default the plugin is trying to access the system `php`-binary and load the `index.php` file as the main entry point.
|
|
44
|
+
However you have the possibility to use an other binary or even compile multiple entry-points:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
usePHP({
|
|
48
|
+
binary: '/opt/lampp/bin/php-8.1.10',
|
|
49
|
+
entry: ['index.php', 'about.php', 'contact.php'],
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Should you have multiple entry-points, you will be able to access each one according to this chart:
|
|
54
|
+
|
|
55
|
+
| Entry file | Accessible routes | Build file |
|
|
56
|
+
| ----------------- | ------------------------------------- | ------------------- |
|
|
57
|
+
| index.php | `/` `/index` `/index.php` | `index.php` |
|
|
58
|
+
| about.php | `/about` `/about.php` | `about.php` |
|
|
59
|
+
| about/details.php | `/about/details` `/about/details.php` | `about/details.php` |
|
|
60
|
+
| contact.php | `/contact` `/contact.php` | `contact.php` |
|
|
61
|
+
| shop/index.php | `/shop/` `/shop/index.php` | `shop/index.php` |
|
|
62
|
+
| ... | ... | ... |
|
|
63
|
+
|
|
64
|
+
## Known issues
|
|
65
|
+
|
|
66
|
+
Vite won't be able to process PHP-computed styles, scripts or images:
|
|
67
|
+
|
|
68
|
+
```php
|
|
69
|
+
<script src="./src/<?='dynamic_script_name';?>.js" type="module"></script>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
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).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const child_process = require('child_process');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
function runPHP(input, args = {}) {
|
|
8
|
+
const params = [runPHP.binary];
|
|
9
|
+
Object.entries(args).forEach(([optionName, value]) => {
|
|
10
|
+
if (optionName === "define") {
|
|
11
|
+
Object.entries(value).forEach(([k, v]) => {
|
|
12
|
+
params.push(`--${optionName} ${k}=${v}`);
|
|
13
|
+
});
|
|
14
|
+
} else {
|
|
15
|
+
const name = optionName.replaceAll("_", "-");
|
|
16
|
+
params.push(`--${name} ${value}`);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
let i = input;
|
|
20
|
+
i = i.replaceAll("'", `'"'"'`);
|
|
21
|
+
i = `echo '${i}' | ` + params.join(" ");
|
|
22
|
+
return child_process.execSync(i).toString();
|
|
23
|
+
}
|
|
24
|
+
runPHP.binary = "php";
|
|
25
|
+
|
|
26
|
+
function makeID() {
|
|
27
|
+
return Date.now().toString(36) + Math.random() * 100;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function writeFile(file, data) {
|
|
31
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
32
|
+
fs.writeFileSync(file, data);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const codeTokens = /* @__PURE__ */ new Map();
|
|
36
|
+
function escapePHP(inputFile, outputFile) {
|
|
37
|
+
const fileId = path.resolve(outputFile);
|
|
38
|
+
const input = fs.readFileSync(inputFile).toString();
|
|
39
|
+
if (!codeTokens.has(fileId)) {
|
|
40
|
+
codeTokens.set(fileId, /* @__PURE__ */ new Map());
|
|
41
|
+
}
|
|
42
|
+
const fileTokens = codeTokens.get(fileId);
|
|
43
|
+
const isJS = inputFile.includes(".js") || inputFile.includes(".ts");
|
|
44
|
+
const isML = inputFile.includes(".php") || inputFile.includes(".htm");
|
|
45
|
+
const out = input.replaceAll(/<\?(?:php|).+?\?>/gi, (match) => {
|
|
46
|
+
let token = makeID();
|
|
47
|
+
if (isJS) {
|
|
48
|
+
token = `/*${token}*/`;
|
|
49
|
+
} else if (isML) {
|
|
50
|
+
token = `<!--${token}-->`;
|
|
51
|
+
}
|
|
52
|
+
fileTokens.set(token, match);
|
|
53
|
+
return token;
|
|
54
|
+
});
|
|
55
|
+
writeFile(outputFile, out);
|
|
56
|
+
}
|
|
57
|
+
function unescapePHP(file) {
|
|
58
|
+
const fileId = path.resolve(file);
|
|
59
|
+
const input = fs.readFileSync(file).toString();
|
|
60
|
+
const fileTokens = codeTokens.get(fileId);
|
|
61
|
+
let out = input;
|
|
62
|
+
if (fileTokens) {
|
|
63
|
+
fileTokens.forEach((code, token) => {
|
|
64
|
+
out = out.replace(token, (match) => {
|
|
65
|
+
return code;
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function usePHP(cfg = {}) {
|
|
73
|
+
const {
|
|
74
|
+
binary = "php",
|
|
75
|
+
entry = "index.php",
|
|
76
|
+
args,
|
|
77
|
+
tempDir = ".php-tmp"
|
|
78
|
+
} = cfg;
|
|
79
|
+
runPHP.binary = binary;
|
|
80
|
+
let config = void 0;
|
|
81
|
+
const entries = Array.isArray(entry) ? entry : [entry];
|
|
82
|
+
function escapeFile(file) {
|
|
83
|
+
const tempFile = `${tempDir}/${file}.html`;
|
|
84
|
+
escapePHP(file, tempFile);
|
|
85
|
+
return tempFile;
|
|
86
|
+
}
|
|
87
|
+
function cleanUp(dir = "") {
|
|
88
|
+
const parentDir = dir ? dir + "/" : dir;
|
|
89
|
+
fs.rmSync(parentDir + tempDir, { recursive: true, force: true });
|
|
90
|
+
}
|
|
91
|
+
return [
|
|
92
|
+
{
|
|
93
|
+
name: "prepare-php",
|
|
94
|
+
config: {
|
|
95
|
+
order: "post",
|
|
96
|
+
handler(config2, env) {
|
|
97
|
+
const gitIgnoreFile = `${tempDir}/.gitignore`;
|
|
98
|
+
if (!fs.existsSync(gitIgnoreFile)) {
|
|
99
|
+
writeFile(gitIgnoreFile, "*\n**/*.php.html");
|
|
100
|
+
}
|
|
101
|
+
const inputs = entries.map(escapeFile);
|
|
102
|
+
return {
|
|
103
|
+
build: {
|
|
104
|
+
rollupOptions: { input: inputs }
|
|
105
|
+
},
|
|
106
|
+
optimizeDeps: { entries: inputs }
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
configResolved(_config) {
|
|
111
|
+
config = _config;
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: "serve-php",
|
|
116
|
+
apply: "serve",
|
|
117
|
+
enforce: "pre",
|
|
118
|
+
configureServer(server) {
|
|
119
|
+
server.middlewares.use(async (req, res, next) => {
|
|
120
|
+
if (req.url) {
|
|
121
|
+
let requestUrl = req.url;
|
|
122
|
+
if (requestUrl.endsWith("/")) {
|
|
123
|
+
requestUrl += "index.php";
|
|
124
|
+
}
|
|
125
|
+
requestUrl = requestUrl.substring(1);
|
|
126
|
+
const entry2 = entries.find((file) => {
|
|
127
|
+
return file === requestUrl || file.substring(0, file.lastIndexOf(".")) === requestUrl;
|
|
128
|
+
});
|
|
129
|
+
if (entry2) {
|
|
130
|
+
let tempFile = `${tempDir}/`;
|
|
131
|
+
tempFile += entry2 + ".html";
|
|
132
|
+
if (fs.existsSync(path.resolve(tempFile))) {
|
|
133
|
+
const code = unescapePHP(tempFile);
|
|
134
|
+
const out = await server.transformIndexHtml(
|
|
135
|
+
requestUrl || "/",
|
|
136
|
+
runPHP(code, args)
|
|
137
|
+
);
|
|
138
|
+
res.end(out);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
next();
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
handleHotUpdate({ server, file }) {
|
|
147
|
+
const entry2 = entries.find(
|
|
148
|
+
(entryFile) => file.endsWith(entryFile) && path.resolve(entryFile) === file
|
|
149
|
+
);
|
|
150
|
+
if (entry2) {
|
|
151
|
+
escapeFile(entry2);
|
|
152
|
+
server.ws.send({
|
|
153
|
+
type: "full-reload",
|
|
154
|
+
path: "*"
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
buildEnd(error) {
|
|
159
|
+
cleanUp();
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: "build-php",
|
|
164
|
+
apply: "build",
|
|
165
|
+
resolveId(source, importer, options) {
|
|
166
|
+
if (importer?.endsWith(".html") && importer.includes(`/${tempDir}/`)) {
|
|
167
|
+
return { id: path.resolve(source) };
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
closeBundle() {
|
|
171
|
+
const distDir = config?.build.outDir;
|
|
172
|
+
entries.forEach((file) => {
|
|
173
|
+
const code = unescapePHP(`${tempDir}/${file}.html`);
|
|
174
|
+
writeFile(`${distDir}/${file}`, code);
|
|
175
|
+
});
|
|
176
|
+
cleanUp(distDir);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
module.exports = usePHP;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
type PHP_CLI_Args = {
|
|
4
|
+
no_chdir?: boolean;
|
|
5
|
+
no_header?: boolean;
|
|
6
|
+
php_ini?: string;
|
|
7
|
+
no_php_ini?: boolean;
|
|
8
|
+
define?: Record<string, string>;
|
|
9
|
+
profile_info?: boolean;
|
|
10
|
+
process_begin?: string;
|
|
11
|
+
process_code?: string;
|
|
12
|
+
process_file?: string;
|
|
13
|
+
process_end?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type UsePHPConfig = {
|
|
17
|
+
binary?: string;
|
|
18
|
+
entry?: string | string[];
|
|
19
|
+
args?: PHP_CLI_Args;
|
|
20
|
+
tempDir?: string;
|
|
21
|
+
};
|
|
22
|
+
declare function usePHP(cfg?: UsePHPConfig): Plugin[];
|
|
23
|
+
|
|
24
|
+
export { usePHP as default };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import { mkdirSync, writeFileSync, readFileSync, existsSync, rmSync } from 'fs';
|
|
3
|
+
import { dirname, resolve } from 'path';
|
|
4
|
+
|
|
5
|
+
function runPHP(input, args = {}) {
|
|
6
|
+
const params = [runPHP.binary];
|
|
7
|
+
Object.entries(args).forEach(([optionName, value]) => {
|
|
8
|
+
if (optionName === "define") {
|
|
9
|
+
Object.entries(value).forEach(([k, v]) => {
|
|
10
|
+
params.push(`--${optionName} ${k}=${v}`);
|
|
11
|
+
});
|
|
12
|
+
} else {
|
|
13
|
+
const name = optionName.replaceAll("_", "-");
|
|
14
|
+
params.push(`--${name} ${value}`);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
let i = input;
|
|
18
|
+
i = i.replaceAll("'", `'"'"'`);
|
|
19
|
+
i = `echo '${i}' | ` + params.join(" ");
|
|
20
|
+
return execSync(i).toString();
|
|
21
|
+
}
|
|
22
|
+
runPHP.binary = "php";
|
|
23
|
+
|
|
24
|
+
function makeID() {
|
|
25
|
+
return Date.now().toString(36) + Math.random() * 100;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function writeFile(file, data) {
|
|
29
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
30
|
+
writeFileSync(file, data);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const codeTokens = /* @__PURE__ */ new Map();
|
|
34
|
+
function escapePHP(inputFile, outputFile) {
|
|
35
|
+
const fileId = resolve(outputFile);
|
|
36
|
+
const input = readFileSync(inputFile).toString();
|
|
37
|
+
if (!codeTokens.has(fileId)) {
|
|
38
|
+
codeTokens.set(fileId, /* @__PURE__ */ new Map());
|
|
39
|
+
}
|
|
40
|
+
const fileTokens = codeTokens.get(fileId);
|
|
41
|
+
const isJS = inputFile.includes(".js") || inputFile.includes(".ts");
|
|
42
|
+
const isML = inputFile.includes(".php") || inputFile.includes(".htm");
|
|
43
|
+
const out = input.replaceAll(/<\?(?:php|).+?\?>/gi, (match) => {
|
|
44
|
+
let token = makeID();
|
|
45
|
+
if (isJS) {
|
|
46
|
+
token = `/*${token}*/`;
|
|
47
|
+
} else if (isML) {
|
|
48
|
+
token = `<!--${token}-->`;
|
|
49
|
+
}
|
|
50
|
+
fileTokens.set(token, match);
|
|
51
|
+
return token;
|
|
52
|
+
});
|
|
53
|
+
writeFile(outputFile, out);
|
|
54
|
+
}
|
|
55
|
+
function unescapePHP(file) {
|
|
56
|
+
const fileId = resolve(file);
|
|
57
|
+
const input = readFileSync(file).toString();
|
|
58
|
+
const fileTokens = codeTokens.get(fileId);
|
|
59
|
+
let out = input;
|
|
60
|
+
if (fileTokens) {
|
|
61
|
+
fileTokens.forEach((code, token) => {
|
|
62
|
+
out = out.replace(token, (match) => {
|
|
63
|
+
return code;
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function usePHP(cfg = {}) {
|
|
71
|
+
const {
|
|
72
|
+
binary = "php",
|
|
73
|
+
entry = "index.php",
|
|
74
|
+
args,
|
|
75
|
+
tempDir = ".php-tmp"
|
|
76
|
+
} = cfg;
|
|
77
|
+
runPHP.binary = binary;
|
|
78
|
+
let config = void 0;
|
|
79
|
+
const entries = Array.isArray(entry) ? entry : [entry];
|
|
80
|
+
function escapeFile(file) {
|
|
81
|
+
const tempFile = `${tempDir}/${file}.html`;
|
|
82
|
+
escapePHP(file, tempFile);
|
|
83
|
+
return tempFile;
|
|
84
|
+
}
|
|
85
|
+
function cleanUp(dir = "") {
|
|
86
|
+
const parentDir = dir ? dir + "/" : dir;
|
|
87
|
+
rmSync(parentDir + tempDir, { recursive: true, force: true });
|
|
88
|
+
}
|
|
89
|
+
return [
|
|
90
|
+
{
|
|
91
|
+
name: "prepare-php",
|
|
92
|
+
config: {
|
|
93
|
+
order: "post",
|
|
94
|
+
handler(config2, env) {
|
|
95
|
+
const gitIgnoreFile = `${tempDir}/.gitignore`;
|
|
96
|
+
if (!existsSync(gitIgnoreFile)) {
|
|
97
|
+
writeFile(gitIgnoreFile, "*\n**/*.php.html");
|
|
98
|
+
}
|
|
99
|
+
const inputs = entries.map(escapeFile);
|
|
100
|
+
return {
|
|
101
|
+
build: {
|
|
102
|
+
rollupOptions: { input: inputs }
|
|
103
|
+
},
|
|
104
|
+
optimizeDeps: { entries: inputs }
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
configResolved(_config) {
|
|
109
|
+
config = _config;
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: "serve-php",
|
|
114
|
+
apply: "serve",
|
|
115
|
+
enforce: "pre",
|
|
116
|
+
configureServer(server) {
|
|
117
|
+
server.middlewares.use(async (req, res, next) => {
|
|
118
|
+
if (req.url) {
|
|
119
|
+
let requestUrl = req.url;
|
|
120
|
+
if (requestUrl.endsWith("/")) {
|
|
121
|
+
requestUrl += "index.php";
|
|
122
|
+
}
|
|
123
|
+
requestUrl = requestUrl.substring(1);
|
|
124
|
+
const entry2 = entries.find((file) => {
|
|
125
|
+
return file === requestUrl || file.substring(0, file.lastIndexOf(".")) === requestUrl;
|
|
126
|
+
});
|
|
127
|
+
if (entry2) {
|
|
128
|
+
let tempFile = `${tempDir}/`;
|
|
129
|
+
tempFile += entry2 + ".html";
|
|
130
|
+
if (existsSync(resolve(tempFile))) {
|
|
131
|
+
const code = unescapePHP(tempFile);
|
|
132
|
+
const out = await server.transformIndexHtml(
|
|
133
|
+
requestUrl || "/",
|
|
134
|
+
runPHP(code, args)
|
|
135
|
+
);
|
|
136
|
+
res.end(out);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
next();
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
handleHotUpdate({ server, file }) {
|
|
145
|
+
const entry2 = entries.find(
|
|
146
|
+
(entryFile) => file.endsWith(entryFile) && resolve(entryFile) === file
|
|
147
|
+
);
|
|
148
|
+
if (entry2) {
|
|
149
|
+
escapeFile(entry2);
|
|
150
|
+
server.ws.send({
|
|
151
|
+
type: "full-reload",
|
|
152
|
+
path: "*"
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
buildEnd(error) {
|
|
157
|
+
cleanUp();
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
name: "build-php",
|
|
162
|
+
apply: "build",
|
|
163
|
+
resolveId(source, importer, options) {
|
|
164
|
+
if (importer?.endsWith(".html") && importer.includes(`/${tempDir}/`)) {
|
|
165
|
+
return { id: resolve(source) };
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
closeBundle() {
|
|
169
|
+
const distDir = config?.build.outDir;
|
|
170
|
+
entries.forEach((file) => {
|
|
171
|
+
const code = unescapePHP(`${tempDir}/${file}.html`);
|
|
172
|
+
writeFile(`${distDir}/${file}`, code);
|
|
173
|
+
});
|
|
174
|
+
cleanUp(distDir);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export { usePHP as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vite-plugin-php",
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Precompile PHP-files with the speed 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
|
+
"loader"
|
|
16
|
+
],
|
|
17
|
+
"author": "Nikita 'donnikitos' Nitichevski <me@donnikitos.com> (https://donnikitos.com/)",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/donnikitos/vite-plugin-php/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/donnikitos/vite-plugin-php#readme",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+ssh://git@github.com/donnikitos/vite-plugin-php.git"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"main": "./dist/index.mjs",
|
|
31
|
+
"module": "./dist/index.mjs",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"import": "./dist/index.mjs",
|
|
37
|
+
"require": "./dist/index.cjs"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "npx unbuild",
|
|
42
|
+
"prepack": "npm run build"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^20.5.1",
|
|
47
|
+
"typescript": "^5.1.6",
|
|
48
|
+
"unbuild": "^1.2.1",
|
|
49
|
+
"vite": "^4.4.9"
|
|
50
|
+
}
|
|
51
|
+
}
|