@stratawp/vite-plugin 0.2.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/README.md +114 -0
- package/dist/index.d.ts +356 -0
- package/dist/index.js +1075 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# @stratawp/vite-plugin
|
|
2
|
+
|
|
3
|
+
Vite plugin for WordPress theme development with StrataWP.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ⚡ **Lightning Fast HMR** - Hot module replacement for JS, CSS, and PHP files
|
|
8
|
+
- 🧩 **Block Auto-Discovery** - Automatically finds and registers Gutenberg blocks
|
|
9
|
+
- 📦 **WordPress Asset Manifest** - Proper dependency management for WordPress
|
|
10
|
+
- 🎨 **Optimized Builds** - WordPress-friendly asset structure
|
|
11
|
+
- 🔄 **PHP File Watching** - See template changes without manual refresh
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add -D @stratawp/vite-plugin
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Basic Setup
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
// vite.config.ts
|
|
25
|
+
import { defineConfig } from 'vite'
|
|
26
|
+
import { strataWP } from '@stratawp/vite-plugin'
|
|
27
|
+
|
|
28
|
+
export default defineConfig({
|
|
29
|
+
plugins: [
|
|
30
|
+
strataWP({
|
|
31
|
+
blocks: {
|
|
32
|
+
dir: 'src/blocks',
|
|
33
|
+
autoRegister: true,
|
|
34
|
+
},
|
|
35
|
+
phpHmr: {
|
|
36
|
+
enabled: true,
|
|
37
|
+
watch: ['**/*.php', 'theme.json'],
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
})
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Options
|
|
45
|
+
|
|
46
|
+
#### Block Options
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
{
|
|
50
|
+
blocks: {
|
|
51
|
+
dir: 'src/blocks', // Block directory
|
|
52
|
+
autoRegister: true, // Auto-register in WordPress
|
|
53
|
+
namespace: 'stratawp', // Block namespace
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
#### PHP HMR Options
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
{
|
|
62
|
+
phpHmr: {
|
|
63
|
+
enabled: true, // Enable PHP watching
|
|
64
|
+
watch: ['**/*.php', 'theme.json'], // Patterns to watch
|
|
65
|
+
debounce: 100, // Debounce delay (ms)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### Manifest Options
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
{
|
|
74
|
+
manifest: {
|
|
75
|
+
enabled: true, // Generate manifest
|
|
76
|
+
output: 'dist/.vite/manifest.json', // Output path
|
|
77
|
+
wordpress: true, // WordPress metadata
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## How It Works
|
|
83
|
+
|
|
84
|
+
### Block Auto-Discovery
|
|
85
|
+
|
|
86
|
+
The plugin scans your `src/blocks` directory for `block.json` files and automatically:
|
|
87
|
+
1. Discovers all blocks
|
|
88
|
+
2. Generates PHP registration code
|
|
89
|
+
3. Watches for changes during development
|
|
90
|
+
4. Rebuilds on block.json modifications
|
|
91
|
+
|
|
92
|
+
### PHP Hot Reload
|
|
93
|
+
|
|
94
|
+
When you modify PHP template files:
|
|
95
|
+
1. Plugin detects the change
|
|
96
|
+
2. Sends reload signal to browser
|
|
97
|
+
3. Page refreshes automatically
|
|
98
|
+
4. Preserves development state where possible
|
|
99
|
+
|
|
100
|
+
### Asset Manifest
|
|
101
|
+
|
|
102
|
+
Generates a WordPress-compatible manifest that includes:
|
|
103
|
+
- File paths and hashes
|
|
104
|
+
- CSS dependencies
|
|
105
|
+
- WordPress script dependencies (wp-element, wp-blocks, etc.)
|
|
106
|
+
- Version strings
|
|
107
|
+
|
|
108
|
+
## Examples
|
|
109
|
+
|
|
110
|
+
See the `examples/` directory in the StrataWP repository for complete working examples.
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
GPL-3.0-or-later
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* StrataWP Plugin Options
|
|
5
|
+
*/
|
|
6
|
+
interface StrataWPPluginOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Block discovery and registration options
|
|
9
|
+
*/
|
|
10
|
+
blocks?: BlockOptions;
|
|
11
|
+
/**
|
|
12
|
+
* Asset manifest generation options
|
|
13
|
+
*/
|
|
14
|
+
manifest?: ManifestOptions;
|
|
15
|
+
/**
|
|
16
|
+
* PHP hot module replacement options
|
|
17
|
+
*/
|
|
18
|
+
phpHmr?: PhpHmrOptions;
|
|
19
|
+
/**
|
|
20
|
+
* Asset handling options
|
|
21
|
+
*/
|
|
22
|
+
assets?: AssetOptions;
|
|
23
|
+
/**
|
|
24
|
+
* Design system integration options
|
|
25
|
+
*/
|
|
26
|
+
designSystem?: DesignSystemOptions;
|
|
27
|
+
/**
|
|
28
|
+
* Performance optimization options
|
|
29
|
+
*/
|
|
30
|
+
performance?: PerformanceOptions;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Block Options
|
|
34
|
+
*/
|
|
35
|
+
interface BlockOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Directory to search for blocks
|
|
38
|
+
* @default 'src/blocks'
|
|
39
|
+
*/
|
|
40
|
+
dir?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Auto-register blocks in WordPress
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
autoRegister?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Block namespace
|
|
48
|
+
* @default 'stratawp'
|
|
49
|
+
*/
|
|
50
|
+
namespace?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Pattern to match block directories
|
|
53
|
+
* @default '* /block.json'
|
|
54
|
+
*/
|
|
55
|
+
pattern?: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Manifest Options
|
|
59
|
+
*/
|
|
60
|
+
interface ManifestOptions {
|
|
61
|
+
/**
|
|
62
|
+
* Enable manifest generation
|
|
63
|
+
* @default true
|
|
64
|
+
*/
|
|
65
|
+
enabled?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Output path for manifest
|
|
68
|
+
* @default 'dist/.vite/manifest.json'
|
|
69
|
+
*/
|
|
70
|
+
output?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Include WordPress-specific metadata
|
|
73
|
+
* @default true
|
|
74
|
+
*/
|
|
75
|
+
wordpress?: boolean;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* PHP HMR Options
|
|
79
|
+
*/
|
|
80
|
+
interface PhpHmrOptions {
|
|
81
|
+
/**
|
|
82
|
+
* Enable PHP file watching
|
|
83
|
+
* @default true
|
|
84
|
+
*/
|
|
85
|
+
enabled?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* File patterns to watch
|
|
88
|
+
* @default ['** /*.php', 'theme.json']
|
|
89
|
+
*/
|
|
90
|
+
watch?: string[];
|
|
91
|
+
/**
|
|
92
|
+
* Debounce delay in ms
|
|
93
|
+
* @default 100
|
|
94
|
+
*/
|
|
95
|
+
debounce?: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Asset Options
|
|
99
|
+
*/
|
|
100
|
+
interface AssetOptions {
|
|
101
|
+
/**
|
|
102
|
+
* Public directory for assets
|
|
103
|
+
* @default 'dist'
|
|
104
|
+
*/
|
|
105
|
+
publicDir?: string;
|
|
106
|
+
/**
|
|
107
|
+
* WordPress assets URL
|
|
108
|
+
*/
|
|
109
|
+
baseUrl?: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Block Metadata (from block.json)
|
|
113
|
+
*/
|
|
114
|
+
interface BlockMetadata {
|
|
115
|
+
apiVersion?: number;
|
|
116
|
+
name: string;
|
|
117
|
+
title: string;
|
|
118
|
+
category: string;
|
|
119
|
+
icon?: string;
|
|
120
|
+
description?: string;
|
|
121
|
+
keywords?: string[];
|
|
122
|
+
attributes?: Record<string, unknown>;
|
|
123
|
+
supports?: Record<string, unknown>;
|
|
124
|
+
editorScript?: string;
|
|
125
|
+
editorStyle?: string;
|
|
126
|
+
script?: string;
|
|
127
|
+
style?: string;
|
|
128
|
+
render?: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* WordPress Asset Manifest Entry
|
|
132
|
+
*/
|
|
133
|
+
interface ManifestEntry {
|
|
134
|
+
file: string;
|
|
135
|
+
src?: string;
|
|
136
|
+
isEntry?: boolean;
|
|
137
|
+
css?: string[];
|
|
138
|
+
assets?: string[];
|
|
139
|
+
dependencies?: string[];
|
|
140
|
+
version?: string;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* WordPress Asset Manifest
|
|
144
|
+
*/
|
|
145
|
+
interface WordPressManifest {
|
|
146
|
+
[key: string]: ManifestEntry;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Design System Options
|
|
150
|
+
*/
|
|
151
|
+
interface DesignSystemOptions {
|
|
152
|
+
/**
|
|
153
|
+
* Enable design system integration
|
|
154
|
+
* @default false
|
|
155
|
+
*/
|
|
156
|
+
enabled?: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* CSS framework to use
|
|
159
|
+
* @default 'none'
|
|
160
|
+
*/
|
|
161
|
+
framework?: 'none' | 'tailwind' | 'unocss';
|
|
162
|
+
/**
|
|
163
|
+
* Path to framework config file
|
|
164
|
+
*/
|
|
165
|
+
configPath?: string;
|
|
166
|
+
/**
|
|
167
|
+
* Enable WordPress preset integration
|
|
168
|
+
* Maps theme.json values to framework
|
|
169
|
+
* @default true
|
|
170
|
+
*/
|
|
171
|
+
wordpressPresets?: boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Custom theme configuration
|
|
174
|
+
*/
|
|
175
|
+
theme?: Record<string, unknown>;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Performance Options
|
|
179
|
+
*/
|
|
180
|
+
interface PerformanceOptions {
|
|
181
|
+
/**
|
|
182
|
+
* Critical CSS extraction options
|
|
183
|
+
* @default true
|
|
184
|
+
*/
|
|
185
|
+
criticalCSS?: boolean | CriticalCSSOptions;
|
|
186
|
+
/**
|
|
187
|
+
* Lazy loading options
|
|
188
|
+
* @default true
|
|
189
|
+
*/
|
|
190
|
+
lazyLoading?: boolean | LazyLoadingOptions;
|
|
191
|
+
/**
|
|
192
|
+
* Asset preloading options
|
|
193
|
+
* @default true
|
|
194
|
+
*/
|
|
195
|
+
preload?: boolean | PreloadOptions;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Critical CSS Options
|
|
199
|
+
*/
|
|
200
|
+
interface CriticalCSSOptions {
|
|
201
|
+
/**
|
|
202
|
+
* Enable critical CSS extraction
|
|
203
|
+
* @default true
|
|
204
|
+
*/
|
|
205
|
+
enabled?: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Templates to process (without .html extension)
|
|
208
|
+
* @default ['index', 'single', 'page', 'archive']
|
|
209
|
+
*/
|
|
210
|
+
templates?: string[];
|
|
211
|
+
/**
|
|
212
|
+
* Viewport dimensions for extraction
|
|
213
|
+
* @default { width: 1300, height: 900 }
|
|
214
|
+
*/
|
|
215
|
+
dimensions?: {
|
|
216
|
+
width: number;
|
|
217
|
+
height: number;
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* Inline critical CSS in HTML
|
|
221
|
+
* @default true
|
|
222
|
+
*/
|
|
223
|
+
inline?: boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Output path for critical CSS files
|
|
226
|
+
* @default 'dist/critical'
|
|
227
|
+
*/
|
|
228
|
+
output?: string;
|
|
229
|
+
/**
|
|
230
|
+
* Minimum size in bytes to extract
|
|
231
|
+
* @default 0
|
|
232
|
+
*/
|
|
233
|
+
minSize?: number;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Lazy Loading Options
|
|
237
|
+
*/
|
|
238
|
+
interface LazyLoadingOptions {
|
|
239
|
+
/**
|
|
240
|
+
* Enable lazy loading
|
|
241
|
+
* @default true
|
|
242
|
+
*/
|
|
243
|
+
enabled?: boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Image lazy loading strategy
|
|
246
|
+
* @default 'native'
|
|
247
|
+
*/
|
|
248
|
+
images?: 'native' | 'intersection-observer' | 'none';
|
|
249
|
+
/**
|
|
250
|
+
* Enable CSS lazy loading
|
|
251
|
+
* @default true
|
|
252
|
+
*/
|
|
253
|
+
css?: boolean;
|
|
254
|
+
/**
|
|
255
|
+
* Enable chunk lazy loading
|
|
256
|
+
* @default true
|
|
257
|
+
*/
|
|
258
|
+
chunks?: boolean;
|
|
259
|
+
/**
|
|
260
|
+
* Placeholder type for images
|
|
261
|
+
* @default 'none'
|
|
262
|
+
*/
|
|
263
|
+
placeholder?: 'blur' | 'color' | 'none';
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Preload Options
|
|
267
|
+
*/
|
|
268
|
+
interface PreloadOptions {
|
|
269
|
+
/**
|
|
270
|
+
* Enable asset preloading
|
|
271
|
+
* @default true
|
|
272
|
+
*/
|
|
273
|
+
enabled?: boolean;
|
|
274
|
+
/**
|
|
275
|
+
* Asset types to preload
|
|
276
|
+
* @default ['fonts', 'critical-css']
|
|
277
|
+
*/
|
|
278
|
+
assets?: Array<'fonts' | 'critical-css' | 'critical-js' | 'images'>;
|
|
279
|
+
/**
|
|
280
|
+
* Preload strategy
|
|
281
|
+
* @default 'link-tag'
|
|
282
|
+
*/
|
|
283
|
+
strategy?: 'link-tag' | 'http2-push';
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Auto-discover and register WordPress blocks
|
|
288
|
+
*/
|
|
289
|
+
declare function strataWPBlocks(options?: BlockOptions): Plugin;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Generate WordPress-compatible asset manifest
|
|
293
|
+
*
|
|
294
|
+
* This manifest helps WordPress properly enqueue Vite-built assets
|
|
295
|
+
* with correct dependencies, versions, and URLs.
|
|
296
|
+
*/
|
|
297
|
+
declare function strataWPManifest(options?: ManifestOptions): Plugin;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Watch PHP files and trigger HMR
|
|
301
|
+
*
|
|
302
|
+
* This allows developers to see changes to PHP templates and theme files
|
|
303
|
+
* without manually refreshing the browser.
|
|
304
|
+
*/
|
|
305
|
+
declare function strataWPPhpHmr(options?: PhpHmrOptions): Plugin;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* WordPress-compatible asset handling
|
|
309
|
+
*
|
|
310
|
+
* Ensures assets are output in WordPress-friendly structure
|
|
311
|
+
* and can be properly enqueued by WordPress.
|
|
312
|
+
*/
|
|
313
|
+
declare function strataWPAssets(options?: AssetOptions): Plugin;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Design System Integration Plugin
|
|
317
|
+
*
|
|
318
|
+
* Integrates Tailwind CSS or UnoCSS with WordPress themes
|
|
319
|
+
*/
|
|
320
|
+
|
|
321
|
+
declare function strataWPDesignSystem(options?: DesignSystemOptions): Plugin;
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Performance Orchestrator
|
|
325
|
+
*
|
|
326
|
+
* Combines all performance plugins with unified configuration
|
|
327
|
+
*/
|
|
328
|
+
|
|
329
|
+
declare function strataWPPerformance(options?: PerformanceOptions): Plugin[];
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* WordPress-aware Tailwind CSS Preset
|
|
333
|
+
*
|
|
334
|
+
* Maps WordPress theme.json values to Tailwind configuration
|
|
335
|
+
*/
|
|
336
|
+
declare const strataWPTailwindPreset: Partial<any>;
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* WordPress-aware UnoCSS Preset
|
|
340
|
+
*
|
|
341
|
+
* Maps WordPress theme.json values to UnoCSS configuration
|
|
342
|
+
*/
|
|
343
|
+
declare const strataWPUnoPreset: any;
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* StrataWP Vite Plugin
|
|
347
|
+
*
|
|
348
|
+
* Provides WordPress-specific build optimizations and development features:
|
|
349
|
+
* - Block auto-discovery and registration
|
|
350
|
+
* - Asset manifest generation for WordPress
|
|
351
|
+
* - PHP file watching with HMR
|
|
352
|
+
* - WordPress-compatible asset URLs
|
|
353
|
+
*/
|
|
354
|
+
declare function strataWP(options?: StrataWPPluginOptions): Plugin[];
|
|
355
|
+
|
|
356
|
+
export { type AssetOptions, type BlockMetadata, type BlockOptions, type CriticalCSSOptions, type DesignSystemOptions, type LazyLoadingOptions, type ManifestEntry, type ManifestOptions, type PerformanceOptions, type PhpHmrOptions, type PreloadOptions, type StrataWPPluginOptions, type WordPressManifest, strataWP, strataWPAssets, strataWPBlocks, strataWPDesignSystem, strataWPManifest, strataWPPerformance, strataWPPhpHmr, strataWPTailwindPreset, strataWPUnoPreset };
|