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

rollup-plugin-reloadsite

v1.0.4

Published

A rollup plugin that adds HMR support via ReloadSite

Downloads

20

Readme

rollup-plugin-reloadsite

Rollup HMR plugin that leverages the power ans simplicity of ReloadSite to provide true HMR capability for your development.

Using rollup-plugin-reloadsite

// import
import hmr from 'rollup-plugin-reloadsite';

module.exports = {
  // add to your plugins array
  plugins: [
    hmr({
      // directories to watch
      dirs: ['./public'],

      //Filtering helps determine the main bundle-file within which the hmr code is added. Otherwise it will be added to all files 
      // This is optional but highly recommended
      // Default is null
      filter: '**/main.js',

      //  the port that ReloadSite uses
      // defaults tp 35729
      port: 35729,

      // How long the server should wait before triggering hot reload
      // This is important when you want to be sure that changes are fully written
      // defaults to 1000
      delay: 1000

    }),
  ],
};

How it works

  1. The plugin uses the process.env.ROLLUP_WATCH to ensure it only runs and adds HMR only on developer mode. Once you get to production, this plugin should silently remove itself from your code.

  2. The plugin uses tcp-port-used to create only one ReloadSite server instance using the port provided in the options.

  3. Then the plugin appends special javascript (Check The Code ) to the files that rollup outputs. This code then appends a script tag that connects to the ReloadSite server created.

    • If you output multiple files, then this code may be repeated in each file but the if condition guards it to run only once.
    • This is precisely why the filter option exists and why you should use it to limit the HMR code to only one file or a few files as you see fit. For example, if your rollup is configured to build different js files for each page, you might want to let the HMR code to be on every page. It is all up to you! Please note that filtering uses picomatch isMatch function and thus you can pass a string or array of patterns.
  4. Once the code in the directories you entered changes, then your application will hot reload. ReloadSite supports HMR as follows:

    • Images and styles are reloaded without refreshing the page by appending a timestamp to the url. Example ?ts=254653476.
    • Javascript files and other code-based files will cause the page to reload. Please see RealoadSite Extensions

Enjoy!