Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hotloader

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hotloader

simple lib for fast html hotloading

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by500%
Maintainers
1
Weekly downloads
 
Created
Source

Hotloader

simple module to enable hot reloading of html. Using a virtual DOM, hotloader diffs changes and mutates the dom. Initial html calls get injected with a socket and hotloading functionality.

hotloader does not care how these html files are created.

example

A full example for hapijs is in the examples folder.

express

const getIndex = cb => fs.readFile('index.html', cb)

// without hotloader
(res, res) => {
  getIndex((_, index) => {
    res.send(index)
  })
}

// with hotloader
(res, res) => {
  hotloader.registerView(
    'index.html',
    getIndex,
    (_, html) => res.send(html)
  )
}

API

const hotloader = require('hotloader')(server.listener)

hotloader.registerView(
  watchFiles,
  getHtml,
  callback
)

The register view function takes 3 arguments

  1. Watch files: passed directly into chokidar.watch. When these files change the page will be updated
  2. getHtml((err, html)), takes a callback, should pass html representing the page being served. This will be called on when file changes are detected
  3. callback. This gets called after register view has finished setting up, as a second argument it will contain the html file that need to be served.

Right now this is experimental. Only use in development.

Rather than for use directly, this should be used to create middleware / plugins (coming soon) to enable hotloading of html..

contributions welcome :)

Keywords

FAQs

Package last updated on 22 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc