@wordpress/build 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/.cache/tsconfig.tsbuildinfo +1 -0
- package/.eslintrc.cjs +8 -0
- package/CHANGELOG.md +14 -0
- package/LICENSE.md +788 -0
- package/README.md +265 -0
- package/package.json +58 -0
- package/src/build.mjs +1345 -0
- package/src/dependency-graph.mjs +271 -0
- package/src/package-utils.mjs +71 -0
- package/src/php-generator.mjs +72 -0
- package/src/wordpress-externals-plugin.mjs +327 -0
- package/templates/index.php.template +31 -0
- package/templates/module-registration.php.template +44 -0
- package/templates/module-registry.php.template +11 -0
- package/templates/script-registration.php.template +87 -0
- package/templates/script-registry.php.template +11 -0
- package/templates/style-registration.php.template +73 -0
- package/templates/style-registry.php.template +11 -0
- package/templates/version.php.template +11 -0
- package/tsconfig.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# @wordpress/build
|
|
2
|
+
|
|
3
|
+
Build tool for WordPress plugins.
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
`@wordpress/build` is an opinionated build system designed for WordPress plugins. It provides:
|
|
8
|
+
|
|
9
|
+
- **Transpilation**: Converts TypeScript/JSX source code to both CommonJS (`build/`) and ESM (`build-module/`) formats using esbuild
|
|
10
|
+
- **Style Compilation**: Processes SCSS files and CSS modules, generating LTR and RTL versions
|
|
11
|
+
- **Bundling**: Creates browser-ready bundles for WordPress scripts and modules
|
|
12
|
+
- **PHP Generation**: Automatically generates PHP registration files for scripts, modules, and styles
|
|
13
|
+
- **Watch Mode**: Incremental rebuilds during development
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @wordpress/build --save-dev
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### Production Build
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
wp-build
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
or via npm script:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "wp-build"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Development Mode (Watch)
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
wp-build --watch
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
or via npm script:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"scripts": {
|
|
50
|
+
"dev": "wp-build --watch"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Package Configuration
|
|
56
|
+
|
|
57
|
+
Configure your `package.json` with the following optional fields:
|
|
58
|
+
|
|
59
|
+
### `wpScript`
|
|
60
|
+
|
|
61
|
+
Set to `true` to bundle the package as a WordPress script/module:
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"wpScript": true
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### `wpScriptModuleExports`
|
|
70
|
+
|
|
71
|
+
Define script module entry points:
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"wpScriptModuleExports": {
|
|
76
|
+
"./interactivity": "./build-module/interactivity/index.js"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### `wpScriptDefaultExport`
|
|
82
|
+
|
|
83
|
+
Handle default export wrapping:
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"wpScriptDefaultExport": true
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### `wpScriptExtraDependencies`
|
|
92
|
+
|
|
93
|
+
Additional script dependencies:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"wpScriptExtraDependencies": ["wp-polyfill"]
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### `wpStyleEntryPoints`
|
|
102
|
+
|
|
103
|
+
Custom SCSS entry point patterns:
|
|
104
|
+
|
|
105
|
+
```json
|
|
106
|
+
{
|
|
107
|
+
"wpStyleEntryPoints": {
|
|
108
|
+
"style": "src/style.scss"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### `wpCopyFiles`
|
|
114
|
+
|
|
115
|
+
Files to copy with optional PHP transformations:
|
|
116
|
+
|
|
117
|
+
```json
|
|
118
|
+
{
|
|
119
|
+
"wpCopyFiles": [
|
|
120
|
+
{
|
|
121
|
+
"from": "src/index.php",
|
|
122
|
+
"to": "build/index.php",
|
|
123
|
+
"transform": "php"
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Root Configuration
|
|
130
|
+
|
|
131
|
+
Configure your root `package.json` with a `wpPlugin` object to control global namespace and externalization behavior:
|
|
132
|
+
|
|
133
|
+
### `wpPlugin.scriptGlobal`
|
|
134
|
+
|
|
135
|
+
The global variable name for your packages (e.g., `"wp"`, `"myPlugin"`). Set to `false` to disable global exposure:
|
|
136
|
+
|
|
137
|
+
```json
|
|
138
|
+
{
|
|
139
|
+
"wpPlugin": {
|
|
140
|
+
"scriptGlobal": "myPlugin"
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### `wpPlugin.packageNamespace`
|
|
146
|
+
|
|
147
|
+
The package scope to match for global exposure (without `@` prefix). Only packages matching `@{packageNamespace}/*` will expose globals:
|
|
148
|
+
|
|
149
|
+
```json
|
|
150
|
+
{
|
|
151
|
+
"wpPlugin": {
|
|
152
|
+
"scriptGlobal": "myPlugin",
|
|
153
|
+
"packageNamespace": "my-plugin"
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### `wpPlugin.handlePrefix`
|
|
159
|
+
|
|
160
|
+
The prefix used for WordPress script handles in `.asset.php` files (e.g., `wp-data`, `my-plugin-editor`). Defaults to `packageNamespace`:
|
|
161
|
+
|
|
162
|
+
```json
|
|
163
|
+
{
|
|
164
|
+
"wpPlugin": {
|
|
165
|
+
"scriptGlobal": "myPlugin",
|
|
166
|
+
"packageNamespace": "my-plugin",
|
|
167
|
+
"handlePrefix": "mp"
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
With this configuration:
|
|
173
|
+
- `@my-plugin/editor` → `window.myPlugin.editor` with handle `mp-editor`
|
|
174
|
+
- `@my-plugin/data` → `window.myPlugin.data` with handle `mp-data`
|
|
175
|
+
|
|
176
|
+
### `wpPlugin.externalNamespaces`
|
|
177
|
+
|
|
178
|
+
Additional package namespaces to externalize (consume as externals, not expose). Each namespace must be an object with `global` and optional `handlePrefix`:
|
|
179
|
+
|
|
180
|
+
```json
|
|
181
|
+
{
|
|
182
|
+
"wpPlugin": {
|
|
183
|
+
"externalNamespaces": {
|
|
184
|
+
"woo": {
|
|
185
|
+
"global": "woo",
|
|
186
|
+
"handlePrefix": "woocommerce"
|
|
187
|
+
},
|
|
188
|
+
"acme": {
|
|
189
|
+
"global": "acme",
|
|
190
|
+
"handlePrefix": "acme-plugin"
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
This allows your packages to consume third-party dependencies as externals:
|
|
198
|
+
- `import { Cart } from '@woo/cart'` → `window.woo.cart` with handle `woocommerce-cart`
|
|
199
|
+
- `import { Button } from '@acme/ui'` → `window.acme.ui` with handle `acme-plugin-ui`
|
|
200
|
+
- Dependencies are tracked in `.asset.php` files
|
|
201
|
+
|
|
202
|
+
If `handlePrefix` is omitted, it defaults to the namespace key (e.g., `"woo"` → `woo-cart`).
|
|
203
|
+
|
|
204
|
+
### Example: WordPress Core (Gutenberg)
|
|
205
|
+
|
|
206
|
+
```json
|
|
207
|
+
{
|
|
208
|
+
"wpPlugin": {
|
|
209
|
+
"scriptGlobal": "wp",
|
|
210
|
+
"packageNamespace": "wordpress"
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
This configuration:
|
|
216
|
+
- Packages like `@wordpress/data` expose `window.wp.data`
|
|
217
|
+
- Packages like `@wordpress/block-editor` expose `window.wp.blockEditor`
|
|
218
|
+
- All packages can consume `@wordpress/*` as externals
|
|
219
|
+
|
|
220
|
+
### Example: Third-Party Plugin
|
|
221
|
+
|
|
222
|
+
```json
|
|
223
|
+
{
|
|
224
|
+
"wpPlugin": {
|
|
225
|
+
"scriptGlobal": "acme",
|
|
226
|
+
"packageNamespace": "acme"
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
This configuration:
|
|
232
|
+
- Packages like `@acme/editor` expose `window.acme.editor`
|
|
233
|
+
- Packages like `@acme/data` expose `window.acme.data`
|
|
234
|
+
- All packages can still consume `@wordpress/*` → `window.wp.*`
|
|
235
|
+
- All packages can still consume vendors (react, lodash) → `window.React`, `window.lodash`
|
|
236
|
+
|
|
237
|
+
### Behavior
|
|
238
|
+
|
|
239
|
+
- **Packages with `wpScript: true` matching the namespace**: Bundled with global exposure
|
|
240
|
+
- **Packages with `wpScript: true` not matching the namespace**: Bundled without global exposure
|
|
241
|
+
- **Dependencies**: `@wordpress/*` packages are always externalized to `wp.*` globals
|
|
242
|
+
- **Vendors**: React, lodash, jQuery, moment are always externalized to their standard globals
|
|
243
|
+
- **Asset files**: `.asset.php` files are always generated for WordPress dependency management
|
|
244
|
+
|
|
245
|
+
## Output Structure
|
|
246
|
+
|
|
247
|
+
The built tool generates several files in the `build/` directory, but the primary output is the PHP registration file.
|
|
248
|
+
|
|
249
|
+
Make sure to include the generated PHP file in your plugin file.
|
|
250
|
+
|
|
251
|
+
```php
|
|
252
|
+
require_once plugin_dir_path( __FILE__ ) . 'build/index.php';
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Contributing to this package
|
|
256
|
+
|
|
257
|
+
This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose.
|
|
258
|
+
|
|
259
|
+
The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects.
|
|
260
|
+
|
|
261
|
+
To find out more about contributing to this package or Gutenberg as a whole, please read the project's main [contributor guide](https://github.com/WordPress/gutenberg/tree/HEAD/CONTRIBUTING.md).
|
|
262
|
+
|
|
263
|
+
## License
|
|
264
|
+
|
|
265
|
+
GPL-2.0-or-later © The WordPress Contributors
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wordpress/build",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Build tool for WordPress plugins.",
|
|
5
|
+
"author": "The WordPress Contributors",
|
|
6
|
+
"license": "GPL-2.0-or-later",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"wordpress",
|
|
9
|
+
"build",
|
|
10
|
+
"esbuild",
|
|
11
|
+
"bundler"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/WordPress/gutenberg/tree/HEAD/packages/wp-build/README.md",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/WordPress/gutenberg.git",
|
|
17
|
+
"directory": "packages/wp-build"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/WordPress/gutenberg/issues"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=20.10.0",
|
|
24
|
+
"npm": ">=10.2.3"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "./src/build.mjs",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"import": "./src/build.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"bin": {
|
|
35
|
+
"wp-build": "./src/build.mjs"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@emotion/babel-plugin": "11.11.0",
|
|
39
|
+
"@types/toposort": "2.0.7",
|
|
40
|
+
"autoprefixer": "10.4.21",
|
|
41
|
+
"browserslist-to-esbuild": "2.1.1",
|
|
42
|
+
"change-case": "4.1.2",
|
|
43
|
+
"chokidar": "^4.0.0",
|
|
44
|
+
"cssnano": "6.0.1",
|
|
45
|
+
"esbuild": "0.25.10",
|
|
46
|
+
"esbuild-plugin-babel": "0.2.3",
|
|
47
|
+
"esbuild-sass-plugin": "3.3.1",
|
|
48
|
+
"fast-glob": "^3.2.7",
|
|
49
|
+
"postcss": "8.4.38",
|
|
50
|
+
"postcss-modules": "6.0.1",
|
|
51
|
+
"rtlcss": "4.3.0",
|
|
52
|
+
"toposort": "2.0.2"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"gitHead": "ceebff807958d2e8fc755b5a20473939c78b4d1d"
|
|
58
|
+
}
|