Skip to content

clappcodes/hmr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@clapp/hmr

Usage

require('@clapp/hmr')(() => {
  require('./your-dev-module');
});
  • callback Function which will be called each time when some file was changed
  • options Options
    • debug Show list of modules which was removed from the cache. Default: false
    • watchDir Relative path to the directory to be watched recursively. Default: directory of the current module
    • watchFilePatterns Files that will trigger reload on change. Default: ["**/*.ts", "**/*.js"]
    • chokidar Chokidar options

Example

route.ts

function route(req: http.Request, res: http.Response): http.RequestListener {
  res.write('Hello World');
  res.end()
});

export default route;

index.ts

import http from 'http';
import hmr from '@clapp/hmr';

let route: http.RequestListener;

hmr(async () => {
  console.log('Reloading app...');
  ({ default: route } = await import('./route'));
});

const server = http.createServer((req, res) => route(req, res));

server.listen(3000);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published