Coder Social home page Coder Social logo

abmsourav / wp-react-hmr-demo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tareq1988/wp-react-hmr-demo

0.0 1.0 1.0 129 KB

A demo WordPress plugin built with React with hot module replacement support.

PHP 27.14% JavaScript 70.99% SCSS 1.87%

wp-react-hmr-demo's Introduction

React HMR WordPress Plugin

A WordPress plugin built with React with hot module replacement support.

Instructions

  1. Clone the repository in your /wp-content/plugins folder.
  2. Install the plugin from /wp-admin/plugins/ page
  3. cd into the repo in your terminal cd wp-react-hmr-demo
  4. Install dependencies by running yarn install

To start developing with HMR support, open your wp-config.php and add this constant:

define( 'WP_LOCAL_DEV', true );

Now run: yarn start

If you navigate to the plugin's menu and start changing your React code, you should see the code updates in realtime. Enjoy!

What is this WP_LOCAL_DEV constant?

When you start the webpack-dev-server with yarn start command, it opens a server in http://localhost:8080 and listens to the changes. The WP_LOCAL_DEV constant helps to detect if we are in the development environment. If configured, the plugin CSS and JS files are served from http://localhost:8080/ instead of your WordPress installation.

When not running yarn start, you should turn the constant to false.

Commands

yarn start: Starts in development mode with HMR support

yarn build: Runs the build in production mode

yarn build:dev: Runs the build in development mode

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.