GithubHelp home page GithubHelp logo

privatenumber / browser-reload-plugin Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 1.0 90 KB

Automatically reload the browser page on every Webpack watch build

License: MIT License

JavaScript 100.00%
webpack plugin reload refresh browser live watch

browser-reload-plugin's Introduction

browser-reload-plugin Latest version Monthly downloads Install size

Automatically reload the browser page on every Webpack watch build

๐Ÿ™‹โ€โ™‚๏ธ Why?

Manually reloading the browser page after your Webpack watch-build finishes is tedious and can really add up.

Speed up development iterations in environments that don't support Hot Module Replacement (HMR) with browser-reload-plugin.

๐Ÿš€ Install

npm i -D browser-reload-plugin

๐Ÿšฆ Quick Setup

All you need is two lines of code to get started with the plugin!

In your development Webpack config:

+ const BrowserReloadPlugin = require('browser-reload-plugin')

  module.exports = {
    ...,

    plugins: [
+     new BrowserReloadPlugin()
    ]
  }

That's it! ๐ŸŽ‰ Just run your watch command to see it in action.

๐ŸŽ› Browser API

The plugin globally exposes a __browserReloadPlugin object that lets you configure the plugin at run-time.

  • enabled (true) - Whether to reload the browser on changes.
  • retryWait (retryWait from plugin options) - How long to wait before re-trying a failed connection on the client-side.
  • wsServer (ws://localhost:PORT) - The WebSocket server address.

You can also reconfigure at run-time by rewriting the object properties. For example:

__browserReloadPlugin.enabled = false;

โš™๏ธ Options

  • port (8080) - Port to bind the servert to. If unavailable, it falls back to a random available port.
  • retryWait (5000) - How long to wait before re-trying a failed connection on the client-side.
  • include (/\.js$/) - A pattern (string | RegExp | [string, RegExp]) to match entry-files to add the client-code to. This is useful if your app has multiple entry-points but you only want the reload client to be added to specific ones.
  • exclude - A pattern (string | RegExp | [string, RegExp]) to exclude certain entry-points.

๐Ÿ’โ€โ™€๏ธ FAQ

Does this work on regular non-watch builds?

No, it's designed specifically for Webpack watch mode.

Should I use this over Hot Module Replacement (HMR)?

HMR is far superior to this approach. Only use this plugin when you have a sophisticated application that doesn't work well with HMR but you'd still like to automate browser page reloads on build.

How is this different from webpack-livereload-plugin?

webpack-livereload-plugin requires adding a <script> tag to your HTML document in order to make live-reload work. This plugin automatically injects itself to the entry-points of your app, and doesn't require any additional setup apart from adding the plugin to the Webpack configuration. It's also much lighter & faster.

browser-reload-plugin's People

Contributors

privatenumber avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

zildjianjax

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.