https://github.com/pqml/hmr-loader
Webpack loader that add a hmr method to your module
https://github.com/pqml/hmr-loader
Last synced: 2 months ago
JSON representation
Webpack loader that add a hmr method to your module
- Host: GitHub
- URL: https://github.com/pqml/hmr-loader
- Owner: pqml
- License: mit
- Created: 2018-03-15T16:23:58.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-25T17:47:26.000Z (almost 7 years ago)
- Last Synced: 2025-01-27T22:15:42.935Z (3 months ago)
- Language: JavaScript
- Size: 13.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hmr-loader
Webpack loader that add a hmr method to your module
## Features
- Wrap your module inside an HMR object
- Watch/Unwatch changes with the `watch` and `unwatch` methods
- Access to your module via the `module` property
## Installation
```sh
$ npm install @internet/hmr -S # with npm
$ yarn add @internet/hmr --dev # with yarn
```
## Usage
:warning: Specify `@internet/hmr` to each import statement your want to add hot reloading.
:warning: `hmr-loader` doesn't work when specified in a webpack config file.
```js
import Module from '@internet/hmr!./module-object'
import string from '@internet/hmr!./module-string'// Return true - you can use it to check if the module is wrapped inside the hmr module
Module.__hmr// Return module ID
Module.id// Real module default value
Module.module// onReload will be called on each reload
Module.watch(onReload)// Stop calling onReload on each reload
Module.unwatch(onReload)// Only the new module value is sent to the callback, without a new hmr wrapper
function onReload (newValue) {}
```
## Requirements
- Node >= 8
- Webpack >= 3
## License
[MIT.](LICENSE)
`hmr-loader` is a package of the [@internet](https://www.npmjs.com/org/internet) npm scope.
_[@internet](https://www.npmjs.com/org/internet) is a collection of opinionated and interoperables front-end npm ES6 modules, with minimal external dependencies._