npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

laravel-elixir-react-hmr

v1.0.4

Published

Laravel Elixir extension for using React with BrowserSync, HMR and React Hot Reload

Downloads

39

Readme

laravel-elixir-react-hmr

Working demo : laravel-elixir-react-hmr-demo

This is for development only. Should not be used on production servers.

For one of my projects, I planned to use Laravel for backend and React for frontend. I decided to use Webpack for bundling all my JS files (to use features like HMR and React Hot Loader for development) and Laravel Elixir for all other assets (css, images, fonts, etc.). I also wanted to use BrowserSync for laravel livereloads and multi-device testing. Thus, I wanted to connect Webpack bundler with Laravel and serve it using BrowserSync.

Jeffery Way has created official Webpack and BrowserSync extensions for Laravel. His Webpack extension does not support webpack-dev-server, HMR and React Hot Loader. Also there is no support for connecting the Webpack output to BrowserSync. I was not able to find any article or package that achieved this. Therefore I decided to develop a Laravel Elixir extension for it.

I am a self-learned programmer/developer and this is my first public package.

Features

  • Laravel 5+ backend server and React frontend
  • Webpack for Javascript compilation and Laravel Elixir for all non-JS assets
  • Multiple input JS files supported (for multi-page application)
  • BrowserSync support (LiveReload non-JS assets, multi-device testing)
  • ES6 and React compilation using Babel
  • Webpack hot module replacement and hot loading of React components (React Hot Loader 3)

Usage

At the moment, users cannot change or provide custom Webpack and BrowserSync configuration.

Step 1 : Install

npm i -D laravel-elixir-react-hmr

Step 2 : Setup

// Add to gulpfile.js
require('laravel-elixir-react-hmr');

Use just like any other Laravel Elixir tasks [i.e. mix.taskName(options)]

elixir(function(mix) {
    mix.react(options);
});

The config options are provided in the form of Javascript object.

Options

// The values given below are the default values
{
    // The URL of your Laravel dev server
    proxy: 'homestead.app',
    
    // List of relative paths (w.r.t '/resources/assets/js') of the input Javascript files
    inputFiles: [
        './app.js'
    ],
    
    // The relative path (w.r.t '/public/js') of the bundled JS output folder
    // The output dir must always be inside the '/public' directory as the application is served from the '/public' dir
    outputDir: './',
    
    // OPTIONAL
    // IP address to use for BrowserSync external URL (used for multi-device access)
    //      Sometimes BrowserSync sets the wrong IP address and external URL doesn't work.
    host: ''
}

Step 3 : Running

To start the BrowserSync server

gulp watch

Open http://localhost:3000 in your browser to load the app. Does not work in IE

Notes

  • Wrapper must be added to the root React component for hot reloading to work (read details)
  • Changes to PHP files will reload the page and the React state would be lost.

Future features

  • Bundling JS for production
  • Custom Webpack config
  • Custom BrowserSync config