iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🙆‍♀️

Easily Create a WordPress Development Environment with wp-env

に公開

Using npm's @wordpress/env, I was able to create a WordPress environment with Docker incredibly easily.
Basically, you just need to set it up according to the official documentation.

https://ja.wordpress.org/team/handbook/block-editor/reference-guides/packages/packages-env/

Install @wordpress/env

# Either install globally
npm -g i @wordpress/env

# Or install in a local project
npm i @wordpress/env --save-dev

Launching the WP Environment

wp-env start

That's it.

However, here are some settings that I personally find useful.

Useful Settings

Write the settings in .wp-env.json.

{
  // Sync local themes
  "themes": [ "./wordpress/wp-content/themes/my_themes" ],
  "mappings": {
    // Settings for folders and files to sync other than themes
    // Sync uploaded files as well
    "wp-content/uploads": "./wordpress/wp-content/uploads",
    // Sync to import DB dump data
    "import.sql": "./import.sql"
  },
  // Add plugins you want to use
  "plugins": [
    "https://downloads.wordpress.org/plugin/advanced-custom-fields.5.9.5.zip",
    "https://downloads.wordpress.org/plugin/no-category-base-wpml.zip",
    "https://downloads.wordpress.org/plugin/wp-pagenavi.2.93.4.zip",
    "https://downloads.wordpress.org/plugin/contact-form-7.5.4.zip",
    "https://downloads.wordpress.org/plugin/flamingo.2.2.1.zip",
    "https://downloads.wordpress.org/plugin/favicon-rotator.zip",
    "https://downloads.wordpress.org/plugin/all-in-one-seo-pack.4.1.0.1.zip",
    "https://downloads.wordpress.org/plugin/custom-post-type-ui.1.9.0.zip",
    "https://downloads.wordpress.org/plugin/taxonomy-terms-order.1.5.7.5.zip",
    "https://downloads.wordpress.org/plugin/custom-post-type-permalinks.3.4.4.zip",
    "https://downloads.wordpress.org/plugin/really-simple-csv-importer.zip",
    "https://downloads.wordpress.org/plugin/rs-csv-importer-media-addon.1.1.0.zip",
    "https://downloads.wordpress.org/plugin/tinymce-advanced.5.6.0.zip"
  ]
}

Importing the DB

Import the synced dump data.

npx wp-env run cli wp db import import.sql

  • This article is a repost from my own blog.

https://akinov.hatenablog.com/entry/2021/04/15/222212

Discussion