@studiometa/foehn-vite-plugin 0.0.1 → 0.5.2
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 +95 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +193 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -4
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# @studiometa/foehn-vite-plugin
|
|
2
|
+
|
|
3
|
+
Vite plugin for the Føhn WordPress framework.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -D @studiometa/foehn-vite-plugin vite
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// vite.config.ts
|
|
15
|
+
import { defineConfig } from "vite";
|
|
16
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
17
|
+
import foehn from "@studiometa/foehn-vite-plugin";
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
plugins: [
|
|
21
|
+
foehn({
|
|
22
|
+
// Glob patterns for entry points
|
|
23
|
+
input: ["src/js/app.js", "src/css/app.css"],
|
|
24
|
+
|
|
25
|
+
// Files to watch for full reload (default: ["templates/**/*.twig"])
|
|
26
|
+
reload: ["templates/**/*.twig", "app/**/*.php"],
|
|
27
|
+
|
|
28
|
+
// Output directory (default: "dist")
|
|
29
|
+
outDir: "dist",
|
|
30
|
+
|
|
31
|
+
// Theme directory context (default: process.cwd())
|
|
32
|
+
themeDir: "./theme",
|
|
33
|
+
}),
|
|
34
|
+
tailwindcss(),
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Features
|
|
40
|
+
|
|
41
|
+
### Glob Input Resolution
|
|
42
|
+
|
|
43
|
+
Input patterns support glob syntax:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
foehn({
|
|
47
|
+
input: ["src/js/*.js", "src/css/*.css"],
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Vite Manifest
|
|
52
|
+
|
|
53
|
+
The plugin enables Vite's native manifest generation (`build.manifest: true`). The manifest is written to `.vite/manifest.json` in the output directory.
|
|
54
|
+
|
|
55
|
+
### Hot Reload
|
|
56
|
+
|
|
57
|
+
During development, the plugin writes a `hot` file containing the dev server URL. The PHP side reads this file to detect dev mode and inject the Vite client script.
|
|
58
|
+
|
|
59
|
+
### File Watching
|
|
60
|
+
|
|
61
|
+
The plugin watches files matching the `reload` patterns and triggers a full page reload when they change. This is useful for PHP and Twig files that don't go through Vite.
|
|
62
|
+
|
|
63
|
+
### DDEV Integration
|
|
64
|
+
|
|
65
|
+
When a `.ddev/config.yaml` file is detected, the plugin automatically configures a proxy to the DDEV site, allowing seamless development with HMR.
|
|
66
|
+
|
|
67
|
+
## Options
|
|
68
|
+
|
|
69
|
+
| Option | Type | Default | Description |
|
|
70
|
+
| ---------- | -------------------- | ------------------------- | --------------------------------- |
|
|
71
|
+
| `input` | `string \| string[]` | _required_ | Entry point glob patterns |
|
|
72
|
+
| `reload` | `string \| string[]` | `["templates/**/*.twig"]` | Patterns to watch for full reload |
|
|
73
|
+
| `outDir` | `string` | `"dist"` | Output directory for built assets |
|
|
74
|
+
| `themeDir` | `string` | `process.cwd()` | Theme directory context |
|
|
75
|
+
| `hotFile` | `string` | `"hot"` | Name of the hot file |
|
|
76
|
+
|
|
77
|
+
## PHP Integration
|
|
78
|
+
|
|
79
|
+
Use the `ViteManifest` helper from the Føhn framework to enqueue assets:
|
|
80
|
+
|
|
81
|
+
```php
|
|
82
|
+
use Studiometa\Foehn\Assets\ViteManifest;
|
|
83
|
+
|
|
84
|
+
#[AsAction("wp_enqueue_scripts")]
|
|
85
|
+
public function enqueueAssets(): void
|
|
86
|
+
{
|
|
87
|
+
ViteManifest::fromTheme()
|
|
88
|
+
->enqueue("src/js/app.js", handle: "theme-app", inFooter: true)
|
|
89
|
+
->enqueue("src/css/app.css", handle: "theme-styles");
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates the Føhn Vite plugin.
|
|
5
|
+
*/
|
|
6
|
+
declare function foehn(options: FoehnPluginOptions): Plugin[];
|
|
7
|
+
export default foehn;
|
|
8
|
+
export { foehn }
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Options for the Føhn Vite plugin.
|
|
12
|
+
*/
|
|
13
|
+
export declare interface FoehnPluginOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Glob patterns for entry points.
|
|
16
|
+
* @example ["src/js/app.js", "src/css/app.css"]
|
|
17
|
+
*/
|
|
18
|
+
input: string | string[];
|
|
19
|
+
/**
|
|
20
|
+
* Files to watch for full reload.
|
|
21
|
+
* @default ["templates/**\/*.twig"]
|
|
22
|
+
*/
|
|
23
|
+
reload?: string | string[];
|
|
24
|
+
/**
|
|
25
|
+
* Output directory for built assets.
|
|
26
|
+
* @default "dist"
|
|
27
|
+
*/
|
|
28
|
+
outDir?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Theme directory context.
|
|
31
|
+
* @default process.cwd()
|
|
32
|
+
*/
|
|
33
|
+
themeDir?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Name of the hot file generated during development.
|
|
36
|
+
* @default "hot"
|
|
37
|
+
*/
|
|
38
|
+
hotFile?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Resolved options with all defaults applied.
|
|
43
|
+
*/
|
|
44
|
+
export declare interface ResolvedFoehnPluginOptions {
|
|
45
|
+
input: string[];
|
|
46
|
+
reload: string[];
|
|
47
|
+
outDir: string;
|
|
48
|
+
themeDir: string;
|
|
49
|
+
hotFile: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { relative, resolve } from "node:path";
|
|
2
|
+
import fastGlob from "fast-glob";
|
|
3
|
+
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
4
|
+
//#region src/options.ts
|
|
5
|
+
/**
|
|
6
|
+
* Default values for optional options.
|
|
7
|
+
*/
|
|
8
|
+
var defaultOptions = {
|
|
9
|
+
reload: ["templates/**/*.twig"],
|
|
10
|
+
outDir: "dist",
|
|
11
|
+
themeDir: process.cwd(),
|
|
12
|
+
hotFile: "hot"
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Normalize and resolve plugin options.
|
|
16
|
+
*/
|
|
17
|
+
function resolveOptions(options) {
|
|
18
|
+
return {
|
|
19
|
+
input: Array.isArray(options.input) ? options.input : [options.input],
|
|
20
|
+
reload: options.reload ? Array.isArray(options.reload) ? options.reload : [options.reload] : defaultOptions.reload,
|
|
21
|
+
outDir: options.outDir ?? defaultOptions.outDir,
|
|
22
|
+
themeDir: options.themeDir ?? defaultOptions.themeDir,
|
|
23
|
+
hotFile: options.hotFile ?? defaultOptions.hotFile
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/utils/glob.ts
|
|
28
|
+
/**
|
|
29
|
+
* Resolve glob patterns to absolute file paths.
|
|
30
|
+
*/
|
|
31
|
+
async function resolveGlobPatterns(patterns, cwd) {
|
|
32
|
+
const entries = {};
|
|
33
|
+
for (const pattern of patterns) if (pattern.includes("*") || pattern.includes("?") || pattern.includes("{")) {
|
|
34
|
+
const files = await fastGlob(pattern, {
|
|
35
|
+
cwd,
|
|
36
|
+
absolute: true
|
|
37
|
+
});
|
|
38
|
+
for (const file of files) {
|
|
39
|
+
const name = relative(cwd, file).replace(/\.[^/.]+$/, "");
|
|
40
|
+
entries[name] = file;
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
const absolutePath = resolve(cwd, pattern);
|
|
44
|
+
const name = pattern.replace(/\.[^/.]+$/, "");
|
|
45
|
+
entries[name] = absolutePath;
|
|
46
|
+
}
|
|
47
|
+
return entries;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/utils/ddev.ts
|
|
51
|
+
/**
|
|
52
|
+
* Detect DDEV configuration from the project root.
|
|
53
|
+
* Returns null if no DDEV config is found.
|
|
54
|
+
*/
|
|
55
|
+
async function detectDdev(projectRoot) {
|
|
56
|
+
const configPath = resolve(projectRoot, ".ddev/config.yaml");
|
|
57
|
+
try {
|
|
58
|
+
return parseDdevConfig(await readFile(configPath, "utf-8"));
|
|
59
|
+
} catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Parse DDEV YAML config (simple parser, no dependency needed).
|
|
65
|
+
*/
|
|
66
|
+
function parseDdevConfig(content) {
|
|
67
|
+
const lines = content.split("\n");
|
|
68
|
+
const config = {};
|
|
69
|
+
for (const line of lines) {
|
|
70
|
+
const match = line.match(/^(\w+):\s*(.+)$/);
|
|
71
|
+
if (match) {
|
|
72
|
+
const key = match[1];
|
|
73
|
+
let value = match[2].trim();
|
|
74
|
+
if (value.startsWith("\"") && value.endsWith("\"") || value.startsWith("'") && value.endsWith("'")) value = value.slice(1, -1);
|
|
75
|
+
config[key] = value;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
name: config.name ?? "unknown",
|
|
80
|
+
router_http_port: config.router_http_port,
|
|
81
|
+
router_https_port: config.router_https_port
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get the DDEV site URL for proxy configuration.
|
|
86
|
+
*/
|
|
87
|
+
function getDdevSiteUrl(config) {
|
|
88
|
+
const port = config.router_https_port ?? "443";
|
|
89
|
+
const portSuffix = port === "443" ? "" : `:${port}`;
|
|
90
|
+
return `https://${config.name}.ddev.site${portSuffix}`;
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/utils/hot.ts
|
|
94
|
+
/**
|
|
95
|
+
* Write the hot file with the dev server URL.
|
|
96
|
+
* The PHP side reads this file to detect dev mode and inject the Vite client.
|
|
97
|
+
*/
|
|
98
|
+
async function writeHotFile(themeDir, hotFileName, serverUrl) {
|
|
99
|
+
const hotPath = resolve(themeDir, hotFileName);
|
|
100
|
+
await writeFile(hotPath, serverUrl, "utf-8");
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Remove the hot file when the dev server stops.
|
|
104
|
+
*/
|
|
105
|
+
async function removeHotFile(themeDir, hotFileName) {
|
|
106
|
+
const hotPath = resolve(themeDir, hotFileName);
|
|
107
|
+
try {
|
|
108
|
+
await unlink(hotPath);
|
|
109
|
+
} catch {}
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/plugin.ts
|
|
113
|
+
/**
|
|
114
|
+
* Creates the Føhn Vite plugin.
|
|
115
|
+
*/
|
|
116
|
+
function foehn(options) {
|
|
117
|
+
const resolvedOptions = resolveOptions(options);
|
|
118
|
+
let config;
|
|
119
|
+
return [{
|
|
120
|
+
name: "foehn",
|
|
121
|
+
enforce: "pre",
|
|
122
|
+
async config(_userConfig, { command: _command }) {
|
|
123
|
+
const entries = await resolveGlobPatterns(resolvedOptions.input, resolvedOptions.themeDir);
|
|
124
|
+
const ddevConfig = await detectDdev(resolvedOptions.themeDir);
|
|
125
|
+
const proxyTarget = ddevConfig ? getDdevSiteUrl(ddevConfig) : void 0;
|
|
126
|
+
return {
|
|
127
|
+
build: {
|
|
128
|
+
manifest: true,
|
|
129
|
+
outDir: resolve(resolvedOptions.themeDir, resolvedOptions.outDir),
|
|
130
|
+
rollupOptions: { input: entries }
|
|
131
|
+
},
|
|
132
|
+
server: proxyTarget ? { proxy: { "^(?!/@|/node_modules|/src)": {
|
|
133
|
+
target: proxyTarget,
|
|
134
|
+
changeOrigin: true,
|
|
135
|
+
secure: false
|
|
136
|
+
} } } : void 0
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
configResolved(resolvedConfig) {
|
|
140
|
+
config = resolvedConfig;
|
|
141
|
+
},
|
|
142
|
+
async configureServer(server) {
|
|
143
|
+
const serverUrl = getServerUrl(server, config);
|
|
144
|
+
server.httpServer?.once("listening", async () => {
|
|
145
|
+
const url = serverUrl ?? `http://localhost:${config.server.port}`;
|
|
146
|
+
await writeHotFile(resolvedOptions.themeDir, resolvedOptions.hotFile, url);
|
|
147
|
+
});
|
|
148
|
+
server.httpServer?.on("close", async () => {
|
|
149
|
+
await removeHotFile(resolvedOptions.themeDir, resolvedOptions.hotFile);
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
async buildEnd() {
|
|
153
|
+
if (config.command === "build") await removeHotFile(resolvedOptions.themeDir, resolvedOptions.hotFile);
|
|
154
|
+
}
|
|
155
|
+
}, createReloadPlugin(resolvedOptions)];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Creates a plugin that watches files for full reload.
|
|
159
|
+
*/
|
|
160
|
+
function createReloadPlugin(options) {
|
|
161
|
+
return {
|
|
162
|
+
name: "foehn:reload",
|
|
163
|
+
configureServer(server) {
|
|
164
|
+
for (const pattern of options.reload) {
|
|
165
|
+
const fullPattern = resolve(options.themeDir, pattern);
|
|
166
|
+
server.watcher.add(fullPattern);
|
|
167
|
+
}
|
|
168
|
+
server.watcher.on("change", (file) => {
|
|
169
|
+
if (options.reload.some((pattern) => {
|
|
170
|
+
return matchPattern(file, resolve(options.themeDir, pattern));
|
|
171
|
+
})) server.ws.send({ type: "full-reload" });
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Simple pattern matching for file paths.
|
|
178
|
+
*/
|
|
179
|
+
function matchPattern(file, pattern) {
|
|
180
|
+
const regexPattern = pattern.replace(/\*\*/g, "<<<GLOBSTAR>>>").replace(/\*/g, "[^/]*").replace(/<<<GLOBSTAR>>>/g, ".*").replace(/\?/g, ".");
|
|
181
|
+
return new RegExp(`^${regexPattern}$`).test(file);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Get the dev server URL.
|
|
185
|
+
*/
|
|
186
|
+
function getServerUrl(server, config) {
|
|
187
|
+
const address = server.httpServer?.address();
|
|
188
|
+
if (typeof address === "object" && address) return `${config.server.https ? "https" : "http"}://${address.address === "::" || address.address === "0.0.0.0" ? "localhost" : address.address}:${address.port}`;
|
|
189
|
+
}
|
|
190
|
+
//#endregion
|
|
191
|
+
export { foehn as default, foehn };
|
|
192
|
+
|
|
193
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/options.ts","../src/utils/glob.ts","../src/utils/ddev.ts","../src/utils/hot.ts","../src/plugin.ts"],"sourcesContent":["/**\n * Options for the Føhn Vite plugin.\n */\nexport interface FoehnPluginOptions {\n /**\n * Glob patterns for entry points.\n * @example [\"src/js/app.js\", \"src/css/app.css\"]\n */\n input: string | string[];\n\n /**\n * Files to watch for full reload.\n * @default [\"templates/**\\/*.twig\"]\n */\n reload?: string | string[];\n\n /**\n * Output directory for built assets.\n * @default \"dist\"\n */\n outDir?: string;\n\n /**\n * Theme directory context.\n * @default process.cwd()\n */\n themeDir?: string;\n\n /**\n * Name of the hot file generated during development.\n * @default \"hot\"\n */\n hotFile?: string;\n}\n\n/**\n * Resolved options with all defaults applied.\n */\nexport interface ResolvedFoehnPluginOptions {\n input: string[];\n reload: string[];\n outDir: string;\n themeDir: string;\n hotFile: string;\n}\n\n/**\n * Default values for optional options.\n */\nexport const defaultOptions: Omit<ResolvedFoehnPluginOptions, \"input\"> = {\n reload: [\"templates/**/*.twig\"],\n outDir: \"dist\",\n themeDir: process.cwd(),\n hotFile: \"hot\",\n};\n\n/**\n * Normalize and resolve plugin options.\n */\nexport function resolveOptions(options: FoehnPluginOptions): ResolvedFoehnPluginOptions {\n const input = Array.isArray(options.input) ? options.input : [options.input];\n\n const reload = options.reload\n ? Array.isArray(options.reload)\n ? options.reload\n : [options.reload]\n : defaultOptions.reload;\n\n return {\n input,\n reload,\n outDir: options.outDir ?? defaultOptions.outDir,\n themeDir: options.themeDir ?? defaultOptions.themeDir,\n hotFile: options.hotFile ?? defaultOptions.hotFile,\n };\n}\n","import fastGlob from \"fast-glob\";\nimport { resolve, relative } from \"node:path\";\n\n/**\n * Resolve glob patterns to absolute file paths.\n */\nexport async function resolveGlobPatterns(\n patterns: string[],\n cwd: string,\n): Promise<Record<string, string>> {\n const entries: Record<string, string> = {};\n\n for (const pattern of patterns) {\n // Check if pattern contains glob characters\n if (pattern.includes(\"*\") || pattern.includes(\"?\") || pattern.includes(\"{\")) {\n const files = await fastGlob(pattern, { cwd, absolute: true });\n for (const file of files) {\n const relativePath = relative(cwd, file);\n // Remove extension for entry name\n const name = relativePath.replace(/\\.[^/.]+$/, \"\");\n entries[name] = file;\n }\n } else {\n // Direct file path\n const absolutePath = resolve(cwd, pattern);\n const name = pattern.replace(/\\.[^/.]+$/, \"\");\n entries[name] = absolutePath;\n }\n }\n\n return entries;\n}\n","import { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\n\n/**\n * DDEV project configuration structure.\n */\nexport interface DdevConfig {\n name: string;\n router_http_port?: string;\n router_https_port?: string;\n}\n\n/**\n * Detect DDEV configuration from the project root.\n * Returns null if no DDEV config is found.\n */\nexport async function detectDdev(projectRoot: string): Promise<DdevConfig | null> {\n const configPath = resolve(projectRoot, \".ddev/config.yaml\");\n\n try {\n const content = await readFile(configPath, \"utf-8\");\n return parseDdevConfig(content);\n } catch {\n return null;\n }\n}\n\n/**\n * Parse DDEV YAML config (simple parser, no dependency needed).\n */\nfunction parseDdevConfig(content: string): DdevConfig {\n const lines = content.split(\"\\n\");\n const config: Record<string, string> = {};\n\n for (const line of lines) {\n const match = line.match(/^(\\w+):\\s*(.+)$/);\n if (match) {\n const key = match[1];\n let value = match[2].trim();\n // Remove quotes if present\n if (\n (value.startsWith('\"') && value.endsWith('\"')) ||\n (value.startsWith(\"'\") && value.endsWith(\"'\"))\n ) {\n value = value.slice(1, -1);\n }\n config[key] = value;\n }\n }\n\n return {\n name: config.name ?? \"unknown\",\n router_http_port: config.router_http_port,\n router_https_port: config.router_https_port,\n };\n}\n\n/**\n * Get the DDEV site URL for proxy configuration.\n */\nexport function getDdevSiteUrl(config: DdevConfig): string {\n const port = config.router_https_port ?? \"443\";\n const portSuffix = port === \"443\" ? \"\" : `:${port}`;\n return `https://${config.name}.ddev.site${portSuffix}`;\n}\n","import { writeFile, unlink } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\n\n/**\n * Write the hot file with the dev server URL.\n * The PHP side reads this file to detect dev mode and inject the Vite client.\n */\nexport async function writeHotFile(\n themeDir: string,\n hotFileName: string,\n serverUrl: string,\n): Promise<void> {\n const hotPath = resolve(themeDir, hotFileName);\n await writeFile(hotPath, serverUrl, \"utf-8\");\n}\n\n/**\n * Remove the hot file when the dev server stops.\n */\nexport async function removeHotFile(themeDir: string, hotFileName: string): Promise<void> {\n const hotPath = resolve(themeDir, hotFileName);\n try {\n await unlink(hotPath);\n } catch {\n // File may not exist, ignore\n }\n}\n","import { resolve } from \"node:path\";\nimport type { Plugin, ResolvedConfig, ViteDevServer } from \"vite\";\nimport type { FoehnPluginOptions, ResolvedFoehnPluginOptions } from \"./options.js\";\nimport { resolveOptions } from \"./options.js\";\nimport {\n resolveGlobPatterns,\n detectDdev,\n getDdevSiteUrl,\n writeHotFile,\n removeHotFile,\n} from \"./utils/index.js\";\n\n/**\n * Creates the Føhn Vite plugin.\n */\nexport function foehn(options: FoehnPluginOptions): Plugin[] {\n const resolvedOptions = resolveOptions(options);\n let config: ResolvedConfig;\n\n const mainPlugin: Plugin = {\n name: \"foehn\",\n enforce: \"pre\",\n\n async config(_userConfig, { command: _command }) {\n const entries = await resolveGlobPatterns(\n resolvedOptions.input,\n resolvedOptions.themeDir,\n );\n\n // Detect DDEV for proxy configuration\n const ddevConfig = await detectDdev(resolvedOptions.themeDir);\n const proxyTarget = ddevConfig ? getDdevSiteUrl(ddevConfig) : undefined;\n\n return {\n build: {\n manifest: true,\n outDir: resolve(resolvedOptions.themeDir, resolvedOptions.outDir),\n rollupOptions: {\n input: entries,\n },\n },\n server: proxyTarget\n ? {\n proxy: {\n // Proxy all non-asset requests to DDEV\n \"^(?!/@|/node_modules|/src)\": {\n target: proxyTarget,\n changeOrigin: true,\n secure: false,\n },\n },\n }\n : undefined,\n };\n },\n\n configResolved(resolvedConfig) {\n config = resolvedConfig;\n },\n\n async configureServer(server: ViteDevServer) {\n const serverUrl = getServerUrl(server, config);\n\n // Write hot file when server starts\n server.httpServer?.once(\"listening\", async () => {\n const url = serverUrl ?? `http://localhost:${config.server.port}`;\n await writeHotFile(resolvedOptions.themeDir, resolvedOptions.hotFile, url);\n });\n\n // Remove hot file when server closes\n server.httpServer?.on(\"close\", async () => {\n await removeHotFile(resolvedOptions.themeDir, resolvedOptions.hotFile);\n });\n },\n\n async buildEnd() {\n // Ensure hot file is removed after build\n if (config.command === \"build\") {\n await removeHotFile(resolvedOptions.themeDir, resolvedOptions.hotFile);\n }\n },\n };\n\n // Separate plugin for file watching (full reload)\n const reloadPlugin = createReloadPlugin(resolvedOptions);\n\n return [mainPlugin, reloadPlugin];\n}\n\n/**\n * Creates a plugin that watches files for full reload.\n */\nfunction createReloadPlugin(options: ResolvedFoehnPluginOptions): Plugin {\n return {\n name: \"foehn:reload\",\n\n configureServer(server: ViteDevServer) {\n // Watch files for full reload\n for (const pattern of options.reload) {\n const fullPattern = resolve(options.themeDir, pattern);\n server.watcher.add(fullPattern);\n }\n\n server.watcher.on(\"change\", (file) => {\n // Check if the changed file matches any reload pattern\n const shouldReload = options.reload.some((pattern) => {\n const fullPattern = resolve(options.themeDir, pattern);\n return matchPattern(file, fullPattern);\n });\n\n if (shouldReload) {\n server.ws.send({ type: \"full-reload\" });\n }\n });\n },\n };\n}\n\n/**\n * Simple pattern matching for file paths.\n */\nfunction matchPattern(file: string, pattern: string): boolean {\n // Convert glob pattern to regex\n const regexPattern = pattern\n .replace(/\\*\\*/g, \"<<<GLOBSTAR>>>\")\n .replace(/\\*/g, \"[^/]*\")\n .replace(/<<<GLOBSTAR>>>/g, \".*\")\n .replace(/\\?/g, \".\");\n\n return new RegExp(`^${regexPattern}$`).test(file);\n}\n\n/**\n * Get the dev server URL.\n */\nfunction getServerUrl(server: ViteDevServer, config: ResolvedConfig): string | undefined {\n const address = server.httpServer?.address();\n if (typeof address === \"object\" && address) {\n const protocol = config.server.https ? \"https\" : \"http\";\n const host =\n address.address === \"::\" || address.address === \"0.0.0.0\"\n ? \"localhost\"\n : address.address;\n return `${protocol}://${host}:${address.port}`;\n }\n return undefined;\n}\n"],"mappings":";;;;;;;AAiDA,IAAa,iBAA4D;CACrE,QAAQ,CAAC,qBAAqB;CAC9B,QAAQ;CACR,UAAU,QAAQ,IAAI;CACtB,SAAS;AACb;;;;AAKA,SAAgB,eAAe,SAAyD;CASpF,OAAO;EACH,OATU,MAAM,QAAQ,QAAQ,KAAK,IAAI,QAAQ,QAAQ,CAAC,QAAQ,KAAK;EAUvE,QARW,QAAQ,SACjB,MAAM,QAAQ,QAAQ,MAAM,IACxB,QAAQ,SACR,CAAC,QAAQ,MAAM,IACnB,eAAe;EAKjB,QAAQ,QAAQ,UAAU,eAAe;EACzC,UAAU,QAAQ,YAAY,eAAe;EAC7C,SAAS,QAAQ,WAAW,eAAe;CAC/C;AACJ;;;;;;ACrEA,eAAsB,oBAClB,UACA,KAC+B;CAC/B,MAAM,UAAkC,CAAC;CAEzC,KAAK,MAAM,WAAW,UAElB,IAAI,QAAQ,SAAS,GAAG,KAAK,QAAQ,SAAS,GAAG,KAAK,QAAQ,SAAS,GAAG,GAAG;EACzE,MAAM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pC;;;;AAKA,SAAS,mBAAmB,SAA6C;CACrE,OAAO;EACH,MAAM;EAEN,gBAAgB,QAAuB;GAEnC,KAAK,MAAM,WAAW,QAAQ,QAAQ;IAClC,MAAM,cAAc,QAAQ,QAAQ,UAAU,OAAO;IACrD,OAAO,QAAQ,IAAI,WAAW;GAClC;GAEA,OAAO,QAAQ,GAAG,WAAW,SAAS;IAOlC,IALqB,QAAQ,OAAO,MAAM,YAAY;KAElD,OAAO,aAAa,MADA,QAAQ,QAAQ,UAAU,OACpB,CAAW;IACzC,CAEI,GACA,OAAO,GAAG,KAAK,EAAE,MAAM,cAAc,CAAC;GAE9C,CAAC;EACL;CACJ;AACJ;;;;AAKA,SAAS,aAAa,MAAc,SAA0B;CAE1D,MAAM,eAAe,QAChB,QAAQ,SAAS,gBAAgB,CAAC,CAClC,QAAQ,OAAO,OAAO,CAAC,CACvB,QAAQ,mBAAmB,IAAI,CAAC,CAChC,QAAQ,OAAO,GAAG;CAEvB,OAAO,IAAI,OAAO,IAAI,aAAa,EAAE,CAAC,CAAC,KAAK,IAAI;AACpD;;;;AAKA,SAAS,aAAa,QAAuB,QAA4C;CACrF,MAAM,UAAU,OAAO,YAAY,QAAQ;CAC3C,IAAI,OAAO,YAAY,YAAY,SAM/B,OAAO,GALU,OAAO,OAAO,QAAQ,UAAU,OAK9B,KAHf,QAAQ,YAAY,QAAQ,QAAQ,YAAY,YAC1C,cACA,QAAQ,QACW,GAAG,QAAQ;AAGhD"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,66 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
"name": "@studiometa/foehn-vite-plugin",
|
|
3
|
+
"version": "0.5.2",
|
|
4
|
+
"description": "Vite plugin for Føhn WordPress framework",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts"
|
|
6
10
|
}
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "vite build",
|
|
22
|
+
"dev": "vite build --watch",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:watch": "vitest",
|
|
25
|
+
"test:coverage": "vitest run --coverage",
|
|
26
|
+
"lint": "oxlint src tests",
|
|
27
|
+
"lint:fix": "oxlint src tests --fix",
|
|
28
|
+
"fmt": "oxfmt --write src tests",
|
|
29
|
+
"fmt:check": "oxfmt --check src tests",
|
|
30
|
+
"typecheck": "tsc --noEmit"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"vite",
|
|
34
|
+
"vite-plugin",
|
|
35
|
+
"wordpress",
|
|
36
|
+
"foehn"
|
|
37
|
+
],
|
|
38
|
+
"author": "Studio Meta <agence@studiometa.fr>",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/studiometa/foehn-framework.git",
|
|
43
|
+
"directory": "packages/vite-plugin"
|
|
44
|
+
},
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/studiometa/foehn-framework/issues"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/studiometa/foehn-framework/tree/main/packages/vite-plugin#readme",
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"fast-glob": "^3.3.0"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@microsoft/api-extractor": "^7.58.12",
|
|
57
|
+
"@types/node": "^26.0.0",
|
|
58
|
+
"@typescript/typescript6": "^6.0.2",
|
|
59
|
+
"oxfmt": "^0.63.0",
|
|
60
|
+
"oxlint": "^1.78.0",
|
|
61
|
+
"typescript": "^7.0.2",
|
|
62
|
+
"vite": "^8.0.0",
|
|
63
|
+
"vite-plugin-dts": "^5.0.0",
|
|
64
|
+
"vitest": "^4.1.0"
|
|
65
|
+
}
|
|
7
66
|
}
|