Skip to content

Commit 036a473

Browse files
feat(env): add .wp-env.json configuration for local development environment
1 parent bdad2ee commit 036a473

3 files changed

Lines changed: 106 additions & 0 deletions

File tree

.wp-env.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
3+
"core": null,
4+
"phpVersion": "8.3",
5+
"themes": [ "." ],
6+
"plugins": [ "https://downloads.wordpress.org/plugin/advanced-custom-fields.zip" ],
7+
"config": {
8+
"WP_DEBUG": true,
9+
"WP_DEBUG_LOG": true,
10+
"WP_DEBUG_DISPLAY": false,
11+
"SCRIPT_DEBUG": true,
12+
"WP_ENVIRONMENT_TYPE": "local",
13+
"WP_DEVELOPMENT_MODE": "theme"
14+
},
15+
"lifecycleScripts": {
16+
"afterStart": "wp-env run cli --env-cwd=wp-content/themes/beapi-frontend-framework composer install --no-interaction"
17+
}
18+
}

README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,86 @@ Alternatively, you can use NPM.
6767
npm install
6868
```
6969

70+
## Local development with wp-env
71+
72+
BFF ships with a [wp-env](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/) configuration (`.wp-env.json`) to run a local WordPress instance with Docker.
73+
74+
### Requirements
75+
76+
- [Docker Desktop](https://www.docker.com/products/docker-desktop/) (or a compatible Docker runtime)
77+
- Node.js (see [Requirements](#nodejs))
78+
79+
### Installing wp-env
80+
81+
You can run wp-env without a global install via `npx @wordpress/env`, or install the CLI once and use the `wp-env` command:
82+
83+
```bash
84+
# Global install (npm or yarn)
85+
npm install -g @wordpress/env
86+
# or
87+
yarn global add @wordpress/env
88+
```
89+
90+
After installation, replace `npx @wordpress/env` with `wp-env` in the commands below.
91+
92+
### Getting started
93+
94+
From the theme root:
95+
96+
```bash
97+
yarn
98+
npx @wordpress/env start
99+
# or, if wp-env is installed globally:
100+
wp-env start
101+
```
102+
103+
On first start, wp-env will:
104+
105+
- Spin up WordPress (PHP 8.3)
106+
- Mount this theme from the current directory
107+
- Install the [Advanced Custom Fields](https://wordpress.org/plugins/advanced-custom-fields/) plugin
108+
- Run `composer install` in the theme via the `afterStart` lifecycle script
109+
110+
### URLs and credentials
111+
112+
| | |
113+
|---|---|
114+
| Site | http://localhost:8888 |
115+
| Admin | http://localhost:8888/wp-admin |
116+
| Username | `admin` |
117+
| Password | `password` |
118+
119+
### Common commands
120+
121+
```bash
122+
# Start the environment
123+
npx @wordpress/env start # or: wp-env start
124+
125+
# Stop containers (data is preserved)
126+
npx @wordpress/env stop # or: wp-env stop
127+
128+
# Remove containers and volumes
129+
npx @wordpress/env destroy # or: wp-env destroy
130+
131+
# Run WP-CLI inside the environment
132+
npx @wordpress/env run cli wp plugin list
133+
# or: wp-env run cli wp plugin list
134+
135+
# Run a command in the theme directory
136+
npx @wordpress/env run cli --env-cwd=wp-content/themes/beapi-frontend-framework composer install
137+
# or: wp-env run cli --env-cwd=wp-content/themes/beapi-frontend-framework composer install
138+
```
139+
140+
### Development workflow
141+
142+
With wp-env running, start the Webpack watcher in a second terminal:
143+
144+
```bash
145+
yarn start
146+
```
147+
148+
Changes to PHP, SCSS, and JavaScript assets are reflected after Webpack rebuilds. Theme PHP changes are picked up immediately thanks to the mounted volume.
149+
70150
## Configuration
71151

72152
The configurations files are in `config` directory.

functions.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<?php
22

3+
if ( ! class_exists( 'BEA\\Theme\\Framework\\Framework', false ) ) {
4+
$autoloader = __DIR__ . '/vendor/autoload.php';
5+
6+
if ( file_exists( $autoloader ) ) {
7+
require_once $autoloader;
8+
}
9+
}
10+
311
/**
412
* Load all services
513
*/

0 commit comments

Comments
 (0)