@10up/wp-vite-plugins 1.0.0-alpha.3 → 1.0.0-alpha.4
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 +338 -0
- package/README.md +84 -58
- package/dist/index.d.ts +400 -366
- package/dist/index.js +4290 -4020
- package/dist/php/wp-boot/Page.php +803 -0
- package/dist/php/wp-boot/Pages.php +133 -0
- package/dist/php/wp-vite-dev-server/Bridge.php +507 -0
- package/dist/php/wp-vite-dev-server/HotFile.php +95 -0
- package/package.json +19 -51
- package/dist/build.d.ts +0 -13
- package/dist/build.js +0 -413
- package/dist/build.js.map +0 -1
- package/dist/cli.js +0 -628
- package/dist/cli.js.map +0 -1
- package/dist/dev.d.ts +0 -35
- package/dist/dev.js +0 -384
- package/dist/dev.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/runner-jUVlAHlZ.d.ts +0 -183
- package/dist/watch.d.ts +0 -12
- package/dist/watch.js +0 -398
- package/dist/watch.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,201 +1,246 @@
|
|
|
1
|
-
import { Plugin } from
|
|
2
|
-
|
|
1
|
+
import { Plugin } from "vite";
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* `
|
|
8
|
-
*
|
|
3
|
+
* Name of the PHP bridge's bootstrap, relative to the resolved `build.outDir`.
|
|
4
|
+
*
|
|
5
|
+
* Written by *both* halves of this module: `wpDevServerPhp` emits it into every
|
|
6
|
+
* build so a consumer's `require_once` is never a dead path, and `wpDevServer`
|
|
7
|
+
* writes the identical bytes on server start so a `dist/` that has never been
|
|
8
|
+
* built still bridges.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEV_SERVER_PHP_NAME = "dev-server.php";
|
|
11
|
+
/**
|
|
12
|
+
* Enables the `@wordpress/build`-style PHP layer next to the built modules:
|
|
13
|
+
* `build.php` (the pages as data) and the `wp-boot/` classes it
|
|
14
|
+
* loads. A consuming plugin then needs no hand-written PHP beyond
|
|
15
|
+
* `require_once __DIR__ . '/dist/build.php';`.
|
|
9
16
|
*/
|
|
10
17
|
interface WpAdminPagesPhpOptions {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Project prefix: names the generated functions and the PHP namespace.
|
|
20
|
+
* Default: `wpPlugin.name` from the consumer's package.json, else its
|
|
21
|
+
* (de-scoped) package name. Dashes are underscored for PHP identifiers;
|
|
22
|
+
* the result must be a valid PHP identifier fragment.
|
|
23
|
+
*/
|
|
24
|
+
prefix?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Script Module id prefix — route modules are registered as
|
|
27
|
+
* `<handlePrefix>/routes/<page>/<route>/{content,route}`.
|
|
28
|
+
* Default: `wpPlugin.handlePrefix`, else `prefix`.
|
|
29
|
+
*/
|
|
30
|
+
handlePrefix?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Raw PHP expression for the URL of the build directory, interpolated
|
|
33
|
+
* into `build.php` verbatim and evaluated on first use. Default
|
|
34
|
+
* `plugin_dir_url( __FILE__ )` (`build.php` lives in the build directory).
|
|
35
|
+
*/
|
|
36
|
+
baseUrl?: string;
|
|
37
|
+
/** Text domain for the menu title's `__()` call. Default `'default'`. */
|
|
38
|
+
textdomain?: string;
|
|
32
39
|
}
|
|
33
40
|
interface WpAdminPagesOptions {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Directory whose immediate subdirectories are pages. A subdirectory is
|
|
43
|
+
* a page when it contains a `content.{tsx,ts,jsx,js}` entry; a sibling
|
|
44
|
+
* `route.{tsx,ts,jsx,js}` is picked up when present, as are additional
|
|
45
|
+
* routes under `<page>/routes/<name>/`.
|
|
46
|
+
*/
|
|
47
|
+
adminPagesDir: string;
|
|
48
|
+
/**
|
|
49
|
+
* Generate the PHP registration layer. Presence enables it; every key
|
|
50
|
+
* is optional.
|
|
51
|
+
*/
|
|
52
|
+
php?: WpAdminPagesPhpOptions;
|
|
53
|
+
/**
|
|
54
|
+
* Root whose `package.json` supplies the `wpPlugin.name` /
|
|
55
|
+
* `wpPlugin.handlePrefix` defaults. Defaults to Vite's `root`, else
|
|
56
|
+
* `process.cwd()`.
|
|
57
|
+
*/
|
|
58
|
+
projectRoot?: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Admin pages are Script Modules: they build in the `modules` environment
|
|
62
|
+
* (see `wpEnvironments`) and contribute nothing to `client`.
|
|
63
|
+
*/
|
|
64
|
+
export declare function wpAdminPages(options: WpAdminPagesOptions): Plugin;
|
|
65
|
+
/** The build environment for classic scripts — Vite's default one. */
|
|
66
|
+
export declare const SCRIPT_ENVIRONMENT = "client";
|
|
67
|
+
/** The build environment for Script Modules. */
|
|
68
|
+
export declare const MODULE_ENVIRONMENT = "modules";
|
|
69
|
+
interface WpEnvironmentsOptions {
|
|
70
|
+
/**
|
|
71
|
+
* Substring matchers for entry source paths that are Script Modules — the
|
|
72
|
+
* same array `wpExternals` takes. An entry of `build.rollupOptions.input`
|
|
73
|
+
* whose (absolute) source path matches one builds in the `modules`
|
|
74
|
+
* environment; every other entry builds as a classic script.
|
|
75
|
+
*
|
|
76
|
+
* Example: `['/assets/js/modules/']`
|
|
77
|
+
*/
|
|
78
|
+
moduleEntryMatchers?: string[];
|
|
58
79
|
}
|
|
59
|
-
declare function
|
|
60
|
-
|
|
80
|
+
export declare function wpEnvironments(options?: WpEnvironmentsOptions): Plugin;
|
|
61
81
|
interface WpBlocksOptions {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
skip?: string[];
|
|
82
|
+
blocksDir: string;
|
|
83
|
+
/**
|
|
84
|
+
* Emit `blocks-manifest.php` (returns one PHP array of all block.json
|
|
85
|
+
* contents). Lets PHP use `wp_register_block_types_from_metadata_collection`
|
|
86
|
+
* (WP 6.7+) instead of N filesystem reads + JSON parses on every request.
|
|
87
|
+
* Default: `true`.
|
|
88
|
+
*/
|
|
89
|
+
emitManifest?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Block directory names (relative to `blocksDir`) to skip entirely —
|
|
92
|
+
* neither discovered as entries, copied, nor included in the manifest.
|
|
93
|
+
*/
|
|
94
|
+
skip?: string[];
|
|
76
95
|
}
|
|
77
|
-
|
|
78
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Each block asset becomes an entry of the environment that builds its kind:
|
|
98
|
+
* `editorScript`/`script`/`viewScript` and the styles in `client`,
|
|
99
|
+
* `scriptModule`/`viewScriptModule` in `modules` (see `wpEnvironments`). The
|
|
100
|
+
* `block.json` copies and the manifest are emitted once, by `client`.
|
|
101
|
+
*/
|
|
102
|
+
export declare function wpBlocks(options: WpBlocksOptions): Plugin;
|
|
79
103
|
interface WpBlockStylesOptions {
|
|
80
|
-
|
|
104
|
+
blocksStylesDir: string;
|
|
105
|
+
/**
|
|
106
|
+
* Output directory, relative to `outDir`, that every stylesheet lands
|
|
107
|
+
* under. Default: `'autoenqueue'` (`dist/autoenqueue/core/group.css`).
|
|
108
|
+
* `10up-toolkit` projects used `'blocks/autoenqueue'`; pass that to keep
|
|
109
|
+
* their PHP enqueue paths unchanged.
|
|
110
|
+
*/
|
|
111
|
+
outputPrefix?: string;
|
|
81
112
|
}
|
|
82
|
-
declare function wpBlockStyles(options: WpBlockStylesOptions): Plugin;
|
|
83
|
-
|
|
113
|
+
export declare function wpBlockStyles(options: WpBlockStylesOptions): Plugin;
|
|
84
114
|
interface WpCopyAssetsOptions {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
/** Only run during the script pass — module pass would emit duplicates. */
|
|
90
|
-
buildType?: 'script' | 'module';
|
|
115
|
+
/** Source directory, e.g. `./assets`. */
|
|
116
|
+
copyAssetsDir: string;
|
|
117
|
+
/** Override the glob pattern (relative to `copyAssetsDir`). */
|
|
118
|
+
pattern?: string;
|
|
91
119
|
}
|
|
92
|
-
declare function wpCopyAssets(options: WpCopyAssetsOptions): Plugin;
|
|
93
|
-
|
|
120
|
+
export declare function wpCopyAssets(options: WpCopyAssetsOptions): Plugin;
|
|
94
121
|
interface ExternalNamespace {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
122
|
+
/** Window global path, e.g. `wp` for `@wordpress/*`, `woo` for `@woo/*`. */
|
|
123
|
+
global: string;
|
|
124
|
+
/** Script-handle prefix used in `.asset.php`. `wp` → `wp-block-editor`. */
|
|
125
|
+
handlePrefix: string;
|
|
99
126
|
}
|
|
100
127
|
interface WpExternalsOptions {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Project root used to resolve `@wordpress/*` (and other) package.jsons.
|
|
130
|
+
* Defaults to `process.cwd()`. Pass the absolute project root for
|
|
131
|
+
* deterministic resolution in monorepos / weird CWDs.
|
|
132
|
+
*/
|
|
133
|
+
projectRoot?: string;
|
|
134
|
+
/**
|
|
135
|
+
* Additional namespaces to externalize. The metadata-driven path covers
|
|
136
|
+
* `@wordpress/*` automatically; this lets you add `woo`, `acme`, etc.
|
|
137
|
+
* as classic-script externals (no metadata read — global/handle config
|
|
138
|
+
* only).
|
|
139
|
+
*/
|
|
140
|
+
externalNamespaces?: Record<string, ExternalNamespace>;
|
|
141
|
+
/**
|
|
142
|
+
* Non-scoped vendor externals (`react`, `jquery`, etc.). These don't
|
|
143
|
+
* carry WP metadata so we keep the hardcoded mapping. Pass `{}` to
|
|
144
|
+
* disable.
|
|
145
|
+
*/
|
|
146
|
+
additionalExternals?: Record<string, {
|
|
147
|
+
global: string;
|
|
148
|
+
handle: string | null;
|
|
149
|
+
}>;
|
|
150
|
+
/**
|
|
151
|
+
* Source paths (substring matchers) of Script Module entries.
|
|
152
|
+
*
|
|
153
|
+
* The mode a file is transformed in normally follows the build
|
|
154
|
+
* environment (see `wpEnvironments`):
|
|
155
|
+
*
|
|
156
|
+
* - `client` rewrites `import { x } from '@wordpress/y'` into
|
|
157
|
+
* `const { x } = window.wp.y;` so the bundle works as a classic
|
|
158
|
+
* <script>. `.asset.php` lists `wp-y`-style handles for
|
|
159
|
+
* `wp_register_script`.
|
|
160
|
+
* - `modules` leaves ESM imports of Script-Module-eligible packages
|
|
161
|
+
* intact (resolved at runtime by WP's import map) for
|
|
162
|
+
* `wp_register_script_module` — required for the Interactivity API and
|
|
163
|
+
* Script Modules generally. `.asset.php` lists those specifiers and
|
|
164
|
+
* includes `'type' => 'module'`. Script-only packages (`wpScript`,
|
|
165
|
+
* vendor globals) have no module form, so they're still rewritten to
|
|
166
|
+
* their `window.*` global with the classic handle recorded.
|
|
167
|
+
*
|
|
168
|
+
* In a build, `wp()` uses these matchers to send the matching entries of
|
|
169
|
+
* `build.rollupOptions.input` to the `modules` environment. The dev server
|
|
170
|
+
* is one environment serving both kinds, so there a file matching one is
|
|
171
|
+
* transformed in module mode and everything else in script mode;
|
|
172
|
+
* `wpDevServer` adds every block and admin-page Script Module it
|
|
173
|
+
* discovers.
|
|
174
|
+
*
|
|
175
|
+
* Example: `['/assets/js/modules/', '/view-module.ts']`
|
|
176
|
+
*/
|
|
177
|
+
moduleEntryMatchers?: string[];
|
|
178
|
+
/**
|
|
179
|
+
* Substring matchers for entry *source* paths (the entry chunk's
|
|
180
|
+
* `facadeModuleId`) whose `.asset.php` should use the
|
|
181
|
+
* `@wordpress/build` shape:
|
|
182
|
+
*
|
|
183
|
+
* 'dependencies' => classic script handles
|
|
184
|
+
* 'module_dependencies' => array( 'id' => …, 'import' => 'static'|'dynamic' )
|
|
185
|
+
*
|
|
186
|
+
* Entries that don't match keep the shape WordPress core reads when it
|
|
187
|
+
* registers a Script Module from `block.json`
|
|
188
|
+
* (`register_block_script_module_id()` passes `dependencies` straight
|
|
189
|
+
* into `wp_register_script_module()`), so module specifiers stay in
|
|
190
|
+
* `dependencies` there.
|
|
191
|
+
*
|
|
192
|
+
* `wp()` wires this automatically for `adminPagesDir`. Set it yourself
|
|
193
|
+
* when composing plugins by hand.
|
|
194
|
+
*
|
|
195
|
+
* Example: `['/assets/js/admin-pages/']`
|
|
196
|
+
*/
|
|
197
|
+
wpBuildAssetMatchers?: string[];
|
|
198
|
+
/**
|
|
199
|
+
* Plugin-local Script Module namespaces — exact names or `prefix-*` globs.
|
|
200
|
+
* Imports matching `@<ns>/<anything>` are externalized as Script Modules:
|
|
201
|
+
* the ESM import is preserved (no global rewrite) and the specifier is
|
|
202
|
+
* recorded in the `.asset.php` dependency list.
|
|
203
|
+
*
|
|
204
|
+
* Example: `['acme-navigation', 'acme-*']`
|
|
205
|
+
*/
|
|
206
|
+
scriptModuleNamespaces?: string[];
|
|
207
|
+
/**
|
|
208
|
+
* What to do with a `@wordpress/*` import whose package is not installed,
|
|
209
|
+
* so there is no metadata to read.
|
|
210
|
+
*
|
|
211
|
+
* - `'bundle'` (default): leave it to Vite, which bundles it or fails
|
|
212
|
+
* with a missing-module error. Install the packages you import.
|
|
213
|
+
* - `'external'`: assume WordPress core provides it, the way
|
|
214
|
+
* `@wordpress/dependency-extraction-webpack-plugin` (and so
|
|
215
|
+
* `10up-toolkit` up to v7) always did. `@wordpress/interactivity` and
|
|
216
|
+
* `@wordpress/interactivity-router` become Script Module imports;
|
|
217
|
+
* every other package becomes `window.wp.<name>` with a `wp-<name>`
|
|
218
|
+
* handle. Packages WordPress does not register, such as
|
|
219
|
+
* `@wordpress/icons` and `@wordpress/dataviews`, are never assumed.
|
|
220
|
+
*/
|
|
221
|
+
uninstalledWordPressPackages?: 'bundle' | 'external';
|
|
222
|
+
/**
|
|
223
|
+
* Populated during the build with specifier → window global for every
|
|
224
|
+
* script-eligible external. `wpScriptIife` uses it to build a `require`
|
|
225
|
+
* shim for CJS deps, which Rolldown resolves at runtime rather than
|
|
226
|
+
* through the import rewrite.
|
|
227
|
+
*/
|
|
228
|
+
globalsSink?: Map<string, string>;
|
|
229
|
+
/**
|
|
230
|
+
* Bare package names to **force-bundle**: their externalization is
|
|
231
|
+
* suppressed and their imports are rewritten to resolve against the
|
|
232
|
+
* installed package's ESM entry instead.
|
|
233
|
+
*
|
|
234
|
+
* The escape hatch for packages whose WP metadata does not match what
|
|
235
|
+
* WordPress core actually registers. Merges with (never replaces)
|
|
236
|
+
* `DEFAULT_BUNDLED_PACKAGES`.
|
|
237
|
+
*
|
|
238
|
+
* Bare names only — `@wordpress/dataviews/wp` and other subpath entries
|
|
239
|
+
* throw at config time, because force-bundling is a whole-package verdict.
|
|
240
|
+
*
|
|
241
|
+
* Example: `['@wordpress/icons', 'some-lying-package']`
|
|
242
|
+
*/
|
|
243
|
+
bundle?: string[];
|
|
199
244
|
}
|
|
200
245
|
/**
|
|
201
246
|
* Packages that claim externalizability they don't have. Same rationale as
|
|
@@ -210,7 +255,7 @@ interface WpExternalsOptions {
|
|
|
210
255
|
* enqueue the script at all. (`@wordpress/icons@11.x` dropped `wpScript`, so
|
|
211
256
|
* without this list the behavior depends on which copy the resolver hoists.)
|
|
212
257
|
*/
|
|
213
|
-
declare const DEFAULT_BUNDLED_PACKAGES: string[];
|
|
258
|
+
export declare const DEFAULT_BUNDLED_PACKAGES: string[];
|
|
214
259
|
/**
|
|
215
260
|
* Config `resolveExternal` needs to make its verdict, extracted so the
|
|
216
261
|
* resolver can be reused outside `wpExternals()` itself (e.g. a dev server
|
|
@@ -218,215 +263,204 @@ declare const DEFAULT_BUNDLED_PACKAGES: string[];
|
|
|
218
263
|
* option defaults.
|
|
219
264
|
*/
|
|
220
265
|
interface ResolveExternalOptions {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
266
|
+
/** Project root used to resolve `@wordpress/*` package.jsons. */
|
|
267
|
+
projectRoot: string;
|
|
268
|
+
/** Vendor external map (`react`, `jquery`, …). Defaults to `DEFAULT_VENDOR`. */
|
|
269
|
+
vendorExternals?: Record<string, {
|
|
270
|
+
global: string;
|
|
271
|
+
handle: string | null;
|
|
272
|
+
}>;
|
|
273
|
+
/** Config-driven classic-script namespaces (`@woo/*`, etc.). */
|
|
274
|
+
externalNamespaces?: Record<string, ExternalNamespace>;
|
|
275
|
+
/** Script Module namespaces — exact names or `prefix-*` globs. */
|
|
276
|
+
scriptModuleNamespaces?: string[];
|
|
277
|
+
/** Bare package names to force-bundle (never externalized). */
|
|
278
|
+
bundledPackages?: ReadonlySet<string> | string[];
|
|
279
|
+
/** See `WpExternalsOptions.uninstalledWordPressPackages`. Default: `'bundle'`. */
|
|
280
|
+
uninstalledWordPressPackages?: 'bundle' | 'external';
|
|
281
|
+
}
|
|
282
|
+
export declare function wpExternals(options?: WpExternalsOptions): Plugin[];
|
|
283
|
+
interface WpCssOptions {
|
|
284
|
+
/**
|
|
285
|
+
* Globs, relative to the Vite root, of the files whose `@custom-media`,
|
|
286
|
+
* `@custom-selector` and `@define-mixin` definitions every stylesheet can
|
|
287
|
+
* use. 10up-toolkit read `assets/css/globals/` and `assets/css/mixins/`.
|
|
288
|
+
*/
|
|
289
|
+
globals?: string[];
|
|
290
|
+
/**
|
|
291
|
+
* Mixins defined in JS: name → declarations. `@mixin <name>;` inserts them.
|
|
292
|
+
* A function is called again whenever the globals are reread.
|
|
293
|
+
*/
|
|
294
|
+
mixins?: MixinMap | (() => MixinMap);
|
|
295
|
+
/**
|
|
296
|
+
* Browserslist query for the compile targets. Default: the project's own
|
|
297
|
+
* browserslist config, or browserslist's `defaults`.
|
|
298
|
+
*/
|
|
299
|
+
browserslist?: string | string[];
|
|
300
|
+
/**
|
|
301
|
+
* The directory whose files are copied into the output directory, keeping
|
|
302
|
+
* their paths (`wp()`'s `copyAssetsDir`). On the dev server, a relative
|
|
303
|
+
* `url()` that points at `<outDir>/images/logo.svg` is served from
|
|
304
|
+
* `<assetsDir>/images/logo.svg`. `wp()` sets it.
|
|
305
|
+
*/
|
|
306
|
+
assetsDir?: string;
|
|
234
307
|
}
|
|
235
|
-
|
|
236
|
-
|
|
308
|
+
type MixinMap = Record<string, Record<string, string | number>>;
|
|
309
|
+
export declare function wpCss(options?: WpCssOptions): Plugin[];
|
|
237
310
|
/**
|
|
238
311
|
* Name of the hot file, relative to the resolved `build.outDir`.
|
|
239
312
|
*
|
|
240
313
|
* Exported because the generated PHP bridge has to spell the same name, and a
|
|
241
314
|
* drifting constant here is a silently dead dev server there.
|
|
242
315
|
*/
|
|
243
|
-
declare const HOT_FILE_NAME = ".wp-vite-dev.json";
|
|
244
|
-
/**
|
|
245
|
-
* Name of the generated PHP bridge, relative to the resolved `build.outDir`.
|
|
246
|
-
*
|
|
247
|
-
* Written by *both* halves of this module: `wpDevServerPhp` emits it into every
|
|
248
|
-
* build so a consumer's `require_once` is never a dead path, and `wpDevServer`
|
|
249
|
-
* writes the identical bytes on server start so a `dist/` that has never been
|
|
250
|
-
* built still bridges.
|
|
251
|
-
*/
|
|
252
|
-
declare const DEV_SERVER_PHP_NAME = "dev-server.php";
|
|
316
|
+
export declare const HOT_FILE_NAME = ".wp-vite-dev.json";
|
|
253
317
|
interface WpDevServerOptions {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
*/
|
|
306
|
-
phpPrefix?: string;
|
|
318
|
+
/** Blocks directory — same value `wpBlocks` gets. Enables block discovery. */
|
|
319
|
+
blocksDir?: string;
|
|
320
|
+
/** Per-block stylesheet directory — same value `wpBlockStyles` gets. */
|
|
321
|
+
blocksStylesDir?: string;
|
|
322
|
+
/** Per-block stylesheet output prefix — same value `wpBlockStyles` gets. */
|
|
323
|
+
blockStylesPrefix?: string;
|
|
324
|
+
/** Admin pages directory — same value `wpAdminPages` gets. */
|
|
325
|
+
adminPagesDir?: string;
|
|
326
|
+
/** Block directory names to skip, mirroring `wpBlocks`' `skip`. */
|
|
327
|
+
skip?: string[];
|
|
328
|
+
/** Write `blocks-manifest.php` into `outDir`. Default: `true`. */
|
|
329
|
+
emitManifest?: boolean;
|
|
330
|
+
/**
|
|
331
|
+
* Root used to resolve `@wordpress/*` package.jsons during the dependency
|
|
332
|
+
* scan. Must match `wpExternals`' `projectRoot` or the two disagree about
|
|
333
|
+
* what is external. Defaults to `process.cwd()`.
|
|
334
|
+
*/
|
|
335
|
+
projectRoot?: string;
|
|
336
|
+
/**
|
|
337
|
+
* The rest of `wpExternals`' externalization config, so the dev scan
|
|
338
|
+
* reaches the same verdicts the build does. `wp()` forwards these.
|
|
339
|
+
*/
|
|
340
|
+
externalNamespaces?: ResolveExternalOptions['externalNamespaces'];
|
|
341
|
+
additionalExternals?: ResolveExternalOptions['vendorExternals'];
|
|
342
|
+
scriptModuleNamespaces?: string[];
|
|
343
|
+
bundledPackages?: string[];
|
|
344
|
+
uninstalledWordPressPackages?: ResolveExternalOptions['uninstalledWordPressPackages'];
|
|
345
|
+
/**
|
|
346
|
+
* Live array shared with `wpExternals`' `moduleEntryMatchers`. An entry of
|
|
347
|
+
* `build.rollupOptions.input` matching one is served as a Script Module,
|
|
348
|
+
* as it builds in the `modules` environment. The plugin also *pushes*
|
|
349
|
+
* every Script Module entry it discovers into it during `configResolved`,
|
|
350
|
+
* which is what makes one dev server serve both kinds of entry correctly —
|
|
351
|
+
* see the note on `syncModuleEntryMatchers()`.
|
|
352
|
+
*/
|
|
353
|
+
moduleEntryMatchers?: string[];
|
|
354
|
+
/**
|
|
355
|
+
* Entry source paths whose sidecar uses the `@wordpress/build` shape,
|
|
356
|
+
* mirroring `wpExternals`' option of the same name. `wp()` wires
|
|
357
|
+
* `adminPagesDir` in automatically.
|
|
358
|
+
*/
|
|
359
|
+
wpBuildAssetMatchers?: string[];
|
|
360
|
+
/** Depth limit for the static import walk. Default: 24. */
|
|
361
|
+
maxScanDepth?: number;
|
|
362
|
+
/**
|
|
363
|
+
* Project prefix for `dev-server.php`: its PHP namespace, script handle,
|
|
364
|
+
* constant and filter.
|
|
365
|
+
* Defaults to `wpPlugin.name`, else the de-scoped `name`, from the
|
|
366
|
+
* package.json at Vite's `root` — else `'wp-vite'`.
|
|
367
|
+
*/
|
|
368
|
+
phpPrefix?: string;
|
|
307
369
|
}
|
|
308
370
|
/** `wpDevServerPhp`'s options — the build-side half of the bridge. */
|
|
309
371
|
interface WpDevServerPhpOptions {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
372
|
+
/** Identifier prefix. Same default as `wpDevServer`'s option of the same name. */
|
|
373
|
+
phpPrefix?: string;
|
|
374
|
+
/** Root whose package.json supplies the prefix default. Defaults to Vite's `root`. */
|
|
375
|
+
projectRoot?: string;
|
|
314
376
|
}
|
|
315
377
|
/** What the hot file contains. Consumed by the generated PHP bridge. */
|
|
316
378
|
interface WpDevServerHotFile {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
379
|
+
/** Scheme + host + port the browser should fetch assets from. No trailing slash. */
|
|
380
|
+
origin: string;
|
|
381
|
+
/** Vite's `base`, with its leading and trailing slash intact (`/` by default). */
|
|
382
|
+
base: string;
|
|
383
|
+
/** Names of the plugins in the resolved config that PHP has to react to. */
|
|
384
|
+
plugins: string[];
|
|
323
385
|
}
|
|
324
|
-
declare function wpDevServer(options?: WpDevServerOptions): Plugin;
|
|
386
|
+
export declare function wpDevServer(options?: WpDevServerOptions): Plugin;
|
|
325
387
|
/**
|
|
326
|
-
* Emit `dist/dev-server.php` — the build-side half of the bridge.
|
|
388
|
+
* Emit `dist/dev-server.php` and its classes — the build-side half of the bridge.
|
|
327
389
|
*
|
|
328
390
|
* Its own plugin, `apply: 'build'`, for one reason: the consumer's PHP holds a
|
|
329
391
|
* single unconditional `require_once __DIR__ . '/dist/dev-server.php'`, and
|
|
330
392
|
* that line has to be true of *every* build — a block plugin with no admin
|
|
331
|
-
* pages, a theme with nothing but a stylesheet entry,
|
|
332
|
-
*
|
|
393
|
+
* pages, a theme with nothing but a stylesheet entry, a plugin with nothing
|
|
394
|
+
* but Script Modules. Emitted by the `client` environment only, which every
|
|
395
|
+
* build has (see `wpEnvironments`). Hanging the emission off `wpAdminPages` (which owns the rest
|
|
333
396
|
* of the generated PHP) or off `wpExternals` (which owns the sidecars the
|
|
334
397
|
* bridge reads) would have made it conditional on something unrelated.
|
|
335
398
|
*
|
|
336
399
|
* The file itself is inert in a built site: nothing writes a hot file next to
|
|
337
400
|
* it, so it returns after one `file_exists()`.
|
|
338
401
|
*/
|
|
339
|
-
declare function wpDevServerPhp(options?: WpDevServerPhpOptions): Plugin;
|
|
340
|
-
|
|
402
|
+
export declare function wpDevServerPhp(options?: WpDevServerPhpOptions): Plugin;
|
|
341
403
|
interface WpOptions {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
404
|
+
blocksDir?: string;
|
|
405
|
+
blocksStylesDir?: string;
|
|
406
|
+
copyAssetsDir?: string;
|
|
407
|
+
adminPagesDir?: string;
|
|
408
|
+
/**
|
|
409
|
+
* Per-plugin escape hatches. Pass `false` to disable; pass an object
|
|
410
|
+
* to merge extra options into the sub-plugin. Nested wins on conflict.
|
|
411
|
+
*/
|
|
412
|
+
blocks?: Partial<WpBlocksOptions> | false;
|
|
413
|
+
blockStyles?: Partial<WpBlockStylesOptions> | false;
|
|
414
|
+
copyAssets?: Partial<WpCopyAssetsOptions> | false;
|
|
415
|
+
adminPages?: Partial<WpAdminPagesOptions> | false;
|
|
416
|
+
externals?: WpExternalsOptions | false;
|
|
417
|
+
/**
|
|
418
|
+
* The `apply: 'serve'` dev-server bridge — hot file, dev `.asset.php`
|
|
419
|
+
* sidecars, blocks metadata, and the bare-specifier escape that keeps
|
|
420
|
+
* Script Module entries servable. Included by default and completely inert
|
|
421
|
+
* in a build; pass `false` to leave dev alone, or an object to override its
|
|
422
|
+
* options (the directories and externals config are wired from the
|
|
423
|
+
* top-level keys automatically).
|
|
424
|
+
*/
|
|
425
|
+
devServer?: WpDevServerOptions | false;
|
|
426
|
+
/**
|
|
427
|
+
* Compile CSS with Lightning CSS instead of PostCSS, with project-wide
|
|
428
|
+
* globals (custom media, custom selectors, mixins) every stylesheet can use
|
|
429
|
+
* without importing them. Off unless set; see `wpCss`.
|
|
430
|
+
*/
|
|
431
|
+
css?: WpCssOptions;
|
|
432
|
+
/** Disable the auto-included script-IIFE helper (classic scripts only). Default: enabled. */
|
|
433
|
+
iife?: false;
|
|
434
|
+
/**
|
|
435
|
+
* Disable the auto-included per-entry module duplication (classic scripts
|
|
436
|
+
* only). Default: enabled. Without it, a module two script entries share becomes a
|
|
437
|
+
* shared chunk each entry `import`s — invalid as a classic script.
|
|
438
|
+
*/
|
|
439
|
+
scriptDedupe?: false;
|
|
440
|
+
/** Disable the auto-included CSS-only-chunk cleanup. Default: always enabled. */
|
|
441
|
+
cleanCssChunks?: false;
|
|
442
|
+
/** Disable the auto-included CSS-only-entry `.asset.php` sidecars. Default: always enabled. */
|
|
443
|
+
cssAssetInfo?: false;
|
|
444
|
+
/**
|
|
445
|
+
* Disable the auto-included guard that keeps byte-identical CSS entries
|
|
446
|
+
* from collapsing into one emitted file. Default: always enabled.
|
|
447
|
+
*/
|
|
448
|
+
cssEntryGuard?: false;
|
|
378
449
|
}
|
|
379
|
-
declare function wp(options?: WpOptions): Plugin[];
|
|
380
|
-
|
|
381
|
-
declare function wpScriptDedupe(): Plugin;
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* vite-plugin-wp-script-iife
|
|
385
|
-
*
|
|
386
|
-
* Wraps each script-mode entry chunk in an IIFE post-write — esbuild/oxc's
|
|
387
|
-
* minifier would otherwise inline a plain intro/outro IIFE for var-heavy
|
|
388
|
-
* bodies, defeating the global-scope isolation needed when WP enqueues
|
|
389
|
-
* these as classic <script> tags.
|
|
390
|
-
*
|
|
391
|
-
* It is also the gate that guarantees the output *is* a valid classic script:
|
|
392
|
-
* every chunk is parsed before it's wrapped, and one that doesn't compile fails
|
|
393
|
-
* the build instead of shipping a file the browser cannot load. The two causes
|
|
394
|
-
* worth diagnosing by name are a live `import`/`export` statement (a shared
|
|
395
|
-
* chunk Rolldown refused to duplicate) and an `import.meta` reference (Vite's
|
|
396
|
-
* dynamic-import preload helper). The `import.meta` members that helper touches
|
|
397
|
-
* are rewritten to classic-script-safe expressions through an injected
|
|
398
|
-
* `define`, so the failure only fires for cases the define can't reach.
|
|
399
|
-
*
|
|
400
|
-
* Only run this in script mode. Module-mode entries (`wp_register_script_module`)
|
|
401
|
-
* must stay as bare ESM for WP's import map to resolve them at runtime.
|
|
402
|
-
*/
|
|
403
|
-
|
|
450
|
+
export declare function wp(options?: WpOptions): Plugin[];
|
|
451
|
+
export declare function wpScriptDedupe(): Plugin;
|
|
404
452
|
interface WpScriptIifeOptions {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
453
|
+
/**
|
|
454
|
+
* Specifier → window global, used to shim `require()` for CJS dependencies
|
|
455
|
+
* whose `require` Rolldown resolves at runtime rather than through
|
|
456
|
+
* `wpExternals`' import rewrite.
|
|
457
|
+
*
|
|
458
|
+
* `wp()` passes `wpExternals`' `globalsSink` automatically.
|
|
459
|
+
*/
|
|
460
|
+
globals?: Map<string, string>;
|
|
413
461
|
}
|
|
414
|
-
declare function wpScriptIife(options?: WpScriptIifeOptions): Plugin;
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
* Deletes the empty `.js` shim Vite leaves next to a CSS-only entry.
|
|
420
|
-
*
|
|
421
|
-
* Vite's Rollup-driven model treats every entry as a JS module that may
|
|
422
|
-
* pull in CSS via side-effect imports. For an entry whose source IS a CSS
|
|
423
|
-
* file (e.g. each per-block stylesheet produced by wpBlockStyles), Vite
|
|
424
|
-
* still emits a tiny empty `.js` chunk that just imports the `.css`.
|
|
425
|
-
* Useless for WP enqueueing.
|
|
426
|
-
*/
|
|
427
|
-
|
|
428
|
-
declare function wpCleanCssChunks(): Plugin;
|
|
429
|
-
|
|
430
|
-
declare function wpCssAssetInfo(): Plugin;
|
|
431
|
-
|
|
432
|
-
export { DEFAULT_BUNDLED_PACKAGES, DEV_SERVER_PHP_NAME, type ExternalNamespace, HOT_FILE_NAME, type WpAdminPagesOptions, type WpAdminPagesPhpOptions, type WpBlockStylesOptions, type WpBlocksOptions, type WpCopyAssetsOptions, type WpDevServerHotFile, type WpDevServerOptions, type WpDevServerPhpOptions, type WpExternalsOptions, type WpOptions, type WpScriptIifeOptions, wp, wpAdminPages, wpBlockStyles, wpBlocks, wpCleanCssChunks, wpCopyAssets, wpCssAssetInfo, wpDevServer, wpDevServerPhp, wpExternals, wpScriptDedupe, wpScriptIife };
|
|
462
|
+
export declare function wpScriptIife(options?: WpScriptIifeOptions): Plugin;
|
|
463
|
+
export declare function wpCleanCssChunks(): Plugin;
|
|
464
|
+
export declare function wpCssAssetInfo(): Plugin;
|
|
465
|
+
export declare function wpCssEntryGuard(): Plugin;
|
|
466
|
+
export type { ExternalNamespace, MixinMap, WpAdminPagesOptions, WpAdminPagesPhpOptions, WpBlockStylesOptions, WpBlocksOptions, WpCopyAssetsOptions, WpCssOptions, WpDevServerHotFile, WpDevServerOptions, WpDevServerPhpOptions, WpEnvironmentsOptions, WpExternalsOptions, WpOptions, WpScriptIifeOptions };
|