https://github.com/clappcodes/hmr
https://github.com/clappcodes/hmr
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/clappcodes/hmr
- Owner: clappcodes
- Created: 2023-12-10T22:43:46.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-13T12:03:27.000Z (over 2 years ago)
- Last Synced: 2025-01-25T20:44:56.826Z (over 1 year ago)
- Language: JavaScript
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# @clapp/hmr
## Usage
```js
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](https://github.com/paulmillr/chokidar#api)
## Example
`route.ts`
```ts
function route(req: http.Request, res: http.Response): http.RequestListener {
res.write('Hello World');
res.end()
});
export default route;
```
`index.ts`
```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);
```