GithubHelp home page GithubHelp logo

isabella232 / wordpress-wasm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wordpress/wordpress-playground

0.0 0.0 0.0 136.27 MB

Run WordPress in the browser thanks to WebAssembly magic

License: Apache License 2.0

Shell 0.02% JavaScript 34.47% C 0.01% PHP 41.23% CSS 22.81% HTML 0.11% Dockerfile 0.01% SCSS 1.34%

wordpress-wasm's Introduction

WordPress in the browser!

See the WordPress.org blog post explaining why is this useful and how does it work for more details. The README doc below is short&sweet for now. Also, explore the early preview on StackBlitz.

Running the demo

This repository ships with a pre-built demo that you can just run!

  1. Clone this repo
  2. Run npm install && npm run dev
  3. Visit http://127.0.0.1:8777/

If you want to build the assembly yourself, follow the instructions below.

This repo draws inspiration from https://github.com/seanmorris/php-wasm and uses https://github.com/aaemnnosttv/wp-sqlite-db

Building the assembly

The build process is split into automated parts. The scripts below create a docker image with the necessary tools, and build PHP as WebAssembly.

Building WASM PHP for the web

npm run build:php:web

Building WASM PHP for node.js

npm run build:php:node

If you'd like to customize the packaged WordPress installation, study and update the build scripts accordingly.

How does it work?

This repo uses four magic ingredients to make WordPress work in the browser:

  1. A WordPress configured to use SQLite instead of MySQL. This is possible thanks to https://github.com/aaemnnosttv/wp-sqlite-db.
  2. A PHP 8.0 compiled with SQLite3 support into WebAssembly.
  3. A PHP + WordPress WebAssembly bundle created using the emscripten toolkit.
  4. A service worker that loads the bundle and dispatches the regular HTTP traffic to the in-memory WordPress instance.

The static files (.js, .css, etc.) are served directly from the host filesystem, not from the WebAssembly bundle.

The work is heavily inspired by https://github.com/seanmorris/php-wasm.

Limitations

The worker applies a series of strange patches to WordPress, it's unclear why they're needed at the moment.

The site editor does not work at the moment. The block editor does, though.

PHP cannot communicate with WordPress.org so the plugin directory etc does not work.

The sqlite database lives in the memory and the changes only live as long as the service worker.

Future work

  • Fix the workarounds mentioned above
  • Remove the static files from the wasm bundle
  • Remove unnecessary PHP extensions to lower the bundle size

wordpress-wasm's People

Contributors

adamziel avatar eliot-akira avatar gziolo avatar johnkennyuk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.