|
1 | 1 | # WordPress in the browser!
|
2 | 2 |
|
3 |
| -See |
4 |
| -[the WordPress.org blog post explaining why is this useful and how does it work](https://make.wordpress.org/core/2022/09/23/client-side-webassembly-wordpress-with-no-server/) for more details. The README doc below is short&sweet for now. Also, [explore the early preview on StackBlitz](https://stackblitz.com/edit/wp-plugin-playground). |
5 |
| - |
6 |
| - |
7 |
| - |
8 |
| - |
9 |
| -## Running the demo |
10 |
| - |
11 |
| -This repository ships with a pre-built demo that you can just run! |
| 3 | +WordPress.wasm is a client-side WordPress that runs without a PHP server thanks to the magic of WebAssembly. |
12 | 4 |
|
13 |
| -1. Clone this repo |
14 |
| -2. Run `npm install && npm run dev` |
15 |
| -3. Visit http://127.0.0.1:8777/ |
| 5 | +[See the live demo!](https://wasm.wordpress.net/wordpress.html) |
16 | 6 |
|
17 |
| -If you want to build the assembly yourself, follow the instructions below. |
18 |
| - |
19 |
| -This repo draws inspiration from https://github.com/seanmorris/php-wasm and uses https://github.com/aaemnnosttv/wp-sqlite-db |
20 |
| - |
21 |
| -## Building the assembly |
22 |
| - |
23 |
| -The build process is split into automated parts. The scripts below create a docker image with the necessary tools, and build PHP as WebAssembly. |
24 |
| - |
25 |
| -### Building WASM PHP for the web |
| 7 | + |
26 | 8 |
|
27 |
| -```bash |
28 |
| -npm run build:php:web |
29 |
| -``` |
30 |
| -### Building WASM PHP for node.js |
| 9 | +Table of contents: |
31 | 10 |
|
32 |
| -```bash |
33 |
| -npm run build:php:node |
34 |
| -``` |
| 11 | +- [Why is this useful?](#why-is-this-useful) |
| 12 | +- [Getting started](#getting-started) |
| 13 | +- [Architecture overview](#architecture-overview) |
35 | 14 |
|
36 |
| -## Building custom WordPress bundle |
| 15 | +## Why is this useful? |
37 | 16 |
|
38 |
| -If you'd like to customize the packaged WordPress installation, update |
39 |
| -the build script at `packages/wordpress-wasm/wordpress/prepare-wordpress.sh`. It generates a bundle called `wp.data`. |
| 17 | +I'm glad you asked – WordPress.wasm is a big deal! |
40 | 18 |
|
41 |
| -For example, before the comment "Prepare WordPress static files": |
| 19 | +WordPress.wasm can power: |
42 | 20 |
|
43 |
| -- Download and extract a plugin zip package |
44 |
| -- Move it into `wp-content/mu-plugins` |
45 |
| -- Add a file that loads the plugin |
| 21 | +* Runeditable code examples in your documentation or course |
| 22 | +* Plugin and theme demos in a private WordPress instance where the user is already logged in as admin |
| 23 | +* Easily switching PHP and WordPress version when testing |
| 24 | +* Replaying and fixing the failed CI tests right in the browser |
46 | 25 |
|
47 |
| -```bash |
48 |
| -plugin_file=example-plugin.1.0.0.zip |
49 |
| -wget https://downloads.wordpress.org/plugin/$plugin_file |
50 |
| -unzip $plugin_file |
51 |
| -rm $plugin_file |
| 26 | +WordPress.wasm provides a strong foundation for the above use-cases but does not implement them just yet. This project is still in its early days and needs contributors. Become a contributor today and help us make these tools a reality! |
52 | 27 |
|
53 |
| -mv example-plugin wordpress/wp-content/plugins/ |
| 28 | +See |
| 29 | +[the WordPress.org blog post](https://make.wordpress.org/core/2022/09/23/client-side-webassembly-wordpress-with-no-server/) to learn about the vision, other use-cases, and the visuals. |
54 | 30 |
|
55 |
| -echo "<?php |
56 |
| -require_once ABSPATH.'wp-content/mu-plugins/example-plugin/example-plugin.php'; |
57 |
| -" > wp-content/mu-plugins/index.php |
58 |
| -``` |
| 31 | +### Getting started |
59 | 32 |
|
60 |
| -To generate a new bundle, run: |
| 33 | +You can run WordPress.wasm as follows: |
61 | 34 |
|
62 |
| -```bash |
63 |
| -npm run build:wp |
| 35 | +```js |
| 36 | +git clone https://github.com/WordPress/wordpress-wasm |
| 37 | +cd wordpress-wasm |
| 38 | +npm install |
| 39 | +npm run dev |
64 | 40 | ```
|
65 | 41 |
|
66 |
| -## How does it work? |
67 |
| - |
68 |
| -This repo uses four magic ingredients to make WordPress work in the browser: |
69 |
| - |
70 |
| -1. A WordPress configured to use SQLite instead of MySQL. This is possible thanks to https://github.com/aaemnnosttv/wp-sqlite-db. |
71 |
| -2. A PHP 8.0 compiled with SQLite3 support into WebAssembly. |
72 |
| -3. A PHP + WordPress WebAssembly bundle created using the emscripten toolkit. |
73 |
| -4. A service worker that loads the bundle and dispatches the regular HTTP traffic to the in-memory WordPress instance. |
74 |
| - |
75 |
| -The static files (.js, .css, etc.) are served directly from the host filesystem, not from the WebAssembly bundle. |
76 |
| - |
77 |
| -The work is *heavily* inspired by https://github.com/seanmorris/php-wasm. |
78 |
| - |
79 |
| -## Limitations |
80 |
| - |
81 |
| -The worker applies a series of strange patches to WordPress, it's unclear why they're needed at the moment. |
82 |
| - |
83 |
| -The site editor does not work at the moment. The block editor does, though. |
| 42 | +A browser should open and take you to your very own client-side WordPress at http://127.0.0.1:8777/wordpress.html! |
84 | 43 |
|
85 |
| -PHP cannot communicate with WordPress.org so the plugin directory etc does not work. |
| 44 | +As of today, the best way to play with WordPress.wasm is to directly modify the cloned files – [packages/wordpress-wasm/](./packages/wordpress-wasm) is a good place to start. |
86 | 45 |
|
87 |
| -The sqlite database lives in the memory and the changes only live as long as the service worker. |
| 46 | +Why aren't there any npm packages? This is a new project and didn't get there yet – all the efforts were focused on getting it to work. If you'd like to see public npm packages sooner than later, you are more than welcome to contribute. |
88 | 47 |
|
89 |
| -## Future work |
| 48 | +## Architecture overview |
90 | 49 |
|
91 |
| -* Fix the workarounds mentioned above |
92 |
| -* Remove the static files from the wasm bundle |
93 |
| -* Remove unnecessary PHP extensions to lower the bundle size |
| 50 | +WordPress.wasm is made of the following building blocks: |
94 | 51 |
|
| 52 | +* [php-wasm](./packages/php-wasm) – a configurable PHP->WebAssembly build pipeline, convenient JavaScript bindings, and a PHP server implemented in JavaScript. |
| 53 | +* [php-wasm-browser](./packages/php-wasm-browser) – tools to run real PHP apps in the browser via `php-wasm`, like a Service Worker implementation or Worker Threads to run the PHP runtime concurrently. |
| 54 | +* [wordpress-wasm](./packages/wordpress-wasm) – runs WordPress in the browser using the other two packages. |
95 | 55 |
|
| 56 | +Consult the linked README.md files in each of these packages to learn more. |
0 commit comments