- Requirements
- Project Structure
- Local Setup
- Installation and Build
- BrowserSync for Live Reloading
- Extending Builds
- Adding a New Package
- Additional Documentation
- PHP: Version 8.4 or higher
- Composer: Install Composer
- Node.js: Version 18.0
- Packages: Contains all project-specific code such as plugins, themes, mu-plugins, and custom libraries. These are built into the
publicdirectory using symlinks via Composer. - Public: Contains files used by WordPress, automatically generated from packages by Composer. This folder should not be modified manually.
- Tools: Contains build and setup scripts used by Codeship and Local.
- Config: Contains environment variable setup files.
-
Create a Git Repository:
- If setting up a new project, create a git repository using Project Base as the template.
-
Create a New Site in Local:
- Enable multisite (subdirectory) if applicable to the project.
-
Navigate to the app folder:
cd app -
Remove the default public folder:
rm -rf public
-
Clone the project into the current folder:
git clone git@github.com:DekodeInteraktiv/{YOUR_PROJECT} . -
Copy the environment example file:
cp .env.example .env
-
Update environment variables in the
.envfile:DB_NAME,DB_USER,DB_PASSWORD,DB_HOSTWP_ENVIRONMENT_TYPE(local, development, staging, production)WP_HOME(e.g.,http://example.com)WP_SITEURL(e.g.,http://example.com/wp)AUTH_KEY,SECURE_AUTH_KEY,LOGGED_IN_KEY,NONCE_KEY,AUTH_SALT,SECURE_AUTH_SALT,LOGGED_IN_SALT,NONCE_SALT
-
Generate security keys (optional, requires wp-cli):
wp package install aaemnnosttv/wp-cli-dotenv-command wp dotenv salts regenerate
Or use the Roots WordPress Salt Generator.
-
Install Composer dependencies:
composer install
-
Install npm dependencies:
npm ci
-
Run local setup scripts (ensure
MYSQLI_DEFAULT_SOCKETis set if needed):cd app/tools/local ./setup-main-site.sh ./activate-plugins.sh bash multisite.sh # Only for multisite setup
-
Update URLs for multisite to use HTTPS:
wp search-replace --url=http://{PROJECT}.site 'http://{PROJECT}.site' 'https://{PROJECT}.site' --recurse-objects --network --skip-columns=guid
-
Navigate to the site app folder and clone the project:
cd path/to/app git clone git@github.com:DekodeInteraktiv/{YOUR_PROJECT} .
-
Remove the default
wp-contentfolder:rm -rf public/wp-content
-
Create a symlink for
wp-content:ln -s ../{project folder}/public/content public/wp-content -
Run local setup scripts:
cd tools/local ./setup-main-site.sh ./activate-plugins.sh bash multisite.sh # Only for multisite setup
To use wp-cli with Local, you can use the built-in site shell. For default system console access, add a wp-cli.local.yml file to the root (app) directory:
path: public/wp
require:
- wp-cli-local.phpSet the MYSQLI_DEFAULT_SOCKET in the .env file using the path from the Local Database tab.
- Start the Environment
npm wp-env startThis command will spin up a local WordPress environment using Docker.
- Scripts
- start:
bash npm run wp-env startStarts the wp-env environment. - stop:
bash npm run wp-env stopStops the wp-env environment. - clean:
bash npm run wp-env cleanRemoves all WordPress data and resets the environment. - destroy:
bash npm run wp-env destroyDestroys the wp-env environment. - logs:
bash npm run wp-env logsDisplays logs from the wp-env environment. - shell:
bash npm run wp-env run cli bashOpens a shell in the wp-env environment. - cli:
bash npm run wp-env run cli <command>Runs a command in the wp-env environment.
- Overriding
.wp-env.jsonwith a Local Setup
To customize your local environment without changing the main .wp-env.json, create a .wp-env.override.json file in your project root. For example:
{
"core": "WordPress/WordPress#6.5",
"plugins": [ "./my-custom-plugin" ],
"mappings": {
"wp-content/uploads": "./uploads"
}
}This file will override or extend the default configuration.
- Dependencies
- Docker: Required to run the environment containers.
Run the following commands in the root directory to build the project:
composer install
npm ci && npm run build(See packages/themes/block-theme for more details)
BrowserSync is included in this project to enable live reloading and synchronized browser testing during development.
BrowserSync is configured via browsersync.config.js and uses environment variables from your .env file:
BROWSER_SYNC_HTTPS: Set totrueto enable HTTPS (default:false).BROWSER_SYNC_PORT: Port for BrowserSync to run on (default:3002).BROWSER_SYNC_PROXY: The local domain to proxy (defaults toWP_HOMEfrom.env).
Example .env settings:
BROWSER_SYNC_HTTPS=true
BROWSER_SYNC_PORT=3002
BROWSER_SYNC_PROXY=your-local-site.testTo start BrowserSync, run:
npm run start-syncThis will watch for changes in CSS, JS, and theme.json files inside packages/, and automatically reload your browser.
Note: Make sure your local site is running and accessible at the proxy URL.
You can modify browsersync.config.js to change watched files or other BrowserSync options as needed.
Project Base uses wp-scripts out of the box for building front-end/view and editor assets. wp-script will scan all block.json files in the src/ folder to find available entries. This means that if you have a src folder with a view.js and a editor.js, you also need to add a block.json file at the same location. Have a look in the block-theme theme for example or read up on wp-script auto discovery for Webpack entry points. For a more advanced setup, you can always customize builds by adding your own webpack.config.js.
- Supply entry points manully to the CLI, e.g.
wp-scripts build src/view src/editor src/admin src/some-other-entry. This will bypass 2 and 3. - Scan
srcfolder for allblock.jsonfiles. (Our default setup). This will support both theme/plugin assets (view/editor) and possible blocks inside thesrc/folder. - Fallback to
src/index.*file. This will only look for asrc/index.jsfile.
-
Create a folder: Add a folder in
./packages(e.g.,./packages/plugins). -
Add a
composer.jsonFile (for themes, plugins, mu-plugins, and PHP dependencies):{ "name": "project/package-name", "description": "Short description of the package.", "type": "wordpress-plugin/wordpress-muplugin/wordpress-theme/other", "version": "1.0.0" }Note: Use block-base for Gutenberg blocks.
Note: A version should always be supplied. This ensures that package versions do not change between branches, leading to unneccesary merge conflicts.
-
Add a
package.jsonFile (for frontend dependencies or custom React components):{ "name": "package-name", "private": true, "version": "1.0.0", "description": "Package description", "author": "Dekode", "main": "index.js", "scripts": { "build": "echo \"Error: no build specified\" && exit 1", "start": "echo \"Error: no start specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1", "clean": "rm -rf node_modules build dist" } } -
Update Root Configuration:
- For Composer packages, add an entry under
"require"incomposer.json:"project/package-name": "@dev"
- For npm packages, add an entry under
"devDependencies"inpackage.json:"package-name": "file:packages/folder/package-name"
- For Composer packages, add an entry under
-
Install the Package:
- For Composer:
composer update
- For npm:
npm install
Re-run
npm run buildornpm run startif needed. - For Composer:
- PostCSS: PostCSS Documentation
- WebPack: WebPack Concepts
- WP Scripts: WP Scripts Guide