proxy-hot-reload

0.3.0 • Public • Published

proxy-hot-reload

Node.js application hot reload with Proxy.

NB: proxy-hot-reload can only proxy modules that return an plain object, like:

module.export = { ... }
// or
exports.xxx = ...

Install

$ npm i proxy-hot-reload --save

Example

app.js

'use strict';
 
if (process.env.NODE_ENV !== 'production') {
  require('proxy-hot-reload')({
    includes: '**/*.js'
  });
}
 
const express = require('express');
const app = express();
const user = require('./user');
 
app.get('/', function (req, res) {
  res.send(user);
})
 
app.listen(3000);

user.js

module.exports = {
  id: 1,
  age: 19
}
DEBUG=proxy-hot-reload node app.js

Then try to modify user.js, access to localhost:3000.

Usage

require('proxy-hot-reload')([option])

option:

  1. includeFiles([obsolute filepath]) || includes(glob pattern string): as PROXY_HOT_RELOAD_INCLUDES, files should be includes, see glob.
  2. excludeFiles([obsolute filepath]) || excludes(glob pattern string): as PROXY_HOT_RELOAD_EXCLUDES, files should be excludes, see glob.
  3. watchedFileChangedButNotReloadCache: default:
function (filename) {
  debug(`${filename} changed, but not reload cache!`)
}

Note

  1. proxy-hot-reload should not be used in production environment.
  2. proxy-hot-reload is effective for some specific files like: lib/*.js, utils/*.js etc.

If you find some bugs please raise an issue or make a pull request.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i proxy-hot-reload

Weekly Downloads

0

Version

0.3.0

License

MIT

Last publish

Collaborators

  • nswbmw