All Projects → vlazh → Node Hot Loader

vlazh / Node Hot Loader

Licence: mit
Hot module replacement (hot reload) for Node.js applications. Develop without server restarting.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Hot Loader

Sass Vars Loader
Use Sass variables defined in Webpack config or in external Javascript or JSON files
Stars: ✭ 112 (+0.9%)
Mutual labels:  webpack, hmr, hot-reload, loader
Angular Hmr
🔥 Angular Hot Module Replacement for Hot Module Reloading
Stars: ✭ 490 (+341.44%)
Mutual labels:  webpack, hmr, hot-reload, loader
Reactly Starter Kit
Deployable React + Webpack 2 starter kit
Stars: ✭ 122 (+9.91%)
Mutual labels:  webpack, express, hot-reload
Reeakt
A modern React boilerplate to awesome web applications
Stars: ✭ 116 (+4.5%)
Mutual labels:  webpack, hmr, express
Template Rwb
A full-featured Webpack setup with hot-reload
Stars: ✭ 165 (+48.65%)
Mutual labels:  webpack, hmr, hot-reload
React Hot Loader Loader
A Webpack Loader that automatically inserts react-hot-loader to your App 👨‍🔬
Stars: ✭ 176 (+58.56%)
Mutual labels:  webpack, hmr, loader
Hot Reload All The Things
Starter project for HMR with backend routes and server/client-side react.
Stars: ✭ 127 (+14.41%)
Mutual labels:  webpack, express, hot-reload
Webpack Dev Server
Serves a webpack app. Updates the browser on changes. Documentation https://webpack.js.org/configuration/dev-server/.
Stars: ✭ 7,250 (+6431.53%)
Mutual labels:  webpack, server, hot-reload
React Ssr Setup
React Starter Project with Webpack 4, Babel 7, TypeScript, CSS Modules, Server Side Rendering, i18n and some more niceties
Stars: ✭ 678 (+510.81%)
Mutual labels:  webpack, hmr, express
Fuse Box
A blazing fast js bundler/loader with a comprehensive API 🔥
Stars: ✭ 4,055 (+3553.15%)
Mutual labels:  hmr, hot-reload, loader
Deprecated
🚀 Framework for building universal web app and static website in Vue.js (beta)
Stars: ✭ 858 (+672.97%)
Mutual labels:  webpack, express, server
Extracted Loader
It reloads extracted stylesheets extracted with ExtractTextPlugin
Stars: ✭ 67 (-39.64%)
Mutual labels:  webpack, hot-reload, loader
Mostly
They mostly come at night; mostly.
Stars: ✭ 78 (-29.73%)
Mutual labels:  webpack, express
Mina Webpack
🍱 Mina single-file-component meets Webpack
Stars: ✭ 77 (-30.63%)
Mutual labels:  webpack, loader
React Dashboard
🔥React Dashboard - isomorphic admin dashboard template (React.js, Bootstrap, Node.js, GraphQL, React Router, Babel, Webpack, Browsersync) 🔥
Stars: ✭ 1,268 (+1042.34%)
Mutual labels:  webpack, hmr
Svelte Template
🚧 An easy-to-use Svelte template! (Svelte + Typescript + Parcel + Express) 2020
Stars: ✭ 88 (-20.72%)
Mutual labels:  hmr, express
Polled.win
📊 Real time polling
Stars: ✭ 76 (-31.53%)
Mutual labels:  webpack, express
Cookiecutter Webpack
Boilerplate for webpack 2, babel, react + redux + hmr, and karma. Can be inserted into existing django projects.
Stars: ✭ 87 (-21.62%)
Mutual labels:  webpack, hmr
Grow Loader
A webpack loader to split class methods by decorators
Stars: ✭ 89 (-19.82%)
Mutual labels:  webpack, loader
Webpack Core Usage
webpack2完整系列课程,欢迎阅读。同时欢迎移步我的react全家桶文章全集: https://github.com/liangklfangl/react-article-bucket
Stars: ✭ 94 (-15.32%)
Mutual labels:  webpack, hmr

Node Hot Loader npm package

Node Hot Loader is a small tool for Hot Module Replacement support for Node.js application development with webpack. Under the hood it uses webpack and babel, so you can use all you need configurations in config files for babel and webpack.

Node Hot Loader, by default, runs all webpack entries in the same single process or in forked process, if you set corresponding option.

The most suitable use case for Node Hot Loader is hot-reloaded express application. Express application can contains API and frontend together, moreover frontend can use own HMR, e.g. React with React Hot Loader. See how to setup React HMR with Express in React Hot Loader docs. Thus, both the frontend and the server will be hot-reloadable.

Node Hot Loader also supports webpack config files written on ES2015+/TypeScript (via babel). For using ES2015+/TypeScript in webpack configuration you have to provide babel configuration file in project root directory.

If you have suggestions or you find a bug, please, open an issue or make a PR.

Installation

npm install --save-dev node-hot-loader webpack
# or
yarn add --dev node-hot-loader webpack

Command line usage

Node Hot Loader uses yargs for parsing command line arguments.

Usage: node-hot {options}

Options

Name Description Note
--config Path to the webpack config file. If not set then search webpack.config.js in root directory.
--fork Launch compiled assets in forked process with optional node exec arguments.
--args List of arguments for forked process.
--autoRestart Auto restart forked process if unaccepted modules discovered.
--inMemory Launch compiled assets in memory fs. Not worked with forked process.
--logLevel Log level related to webpack stats configuration presets names. If not set then uses webpack stats configuration.

Usage example

node-hot --config webpack.config.server.js
# or
node-hot --logLevel minimal
# or
node-hot --fork
# or
node-hot --fork --autoRestart
# or
node-hot --fork=--arg1,--arg2 --
# or
node-hot --fork --args=--arg1,--arg2
# or just
node-hot
# Use the --help option to get the list of available options

Of course, you can add script into you package.json:

...
"scripts": {
  "start": "node-hot --config webpack.config.server.js"
}
...

and then run with your favorite package manager:

npm run start
# or
yarn run start

Webpack plugin

import NodeHotLoaderWebpackPlugin from 'node-hot-loader/NodeHotLoaderWebpackPlugin';

// Webpack configuration
export default {
  plugins: [
    // All options are optional
    new NodeHotLoaderWebpackPlugin({
      force, // boolean. true - always launch entries, false (by default) - launch entries only in watch mode.
      fork, // boolean | string[]. For example ['--key', 'key value'].
      args, // string[]. For example ['--arg1', 'arg2'].
      autoRestart, // boolean
      logLevel, // string
    }),
  ],
};

and run webpack in watch mode:

webpack --watch

The minimum required configuration:

Node Hot Loader adds all necessaries to webpack config if not present already (e.g. HotModuleReplacementPlugin), but it's require the minimum configuration in your webpack config file:

export default {
  output: {
    // Webpack can't find hot-update if output file is not directly in output.path.
    // For example, filename: 'js/[name].js' will not work.
    // However, I have no many tests for that.
    filename: '[name].js',
  },
};

Express Hot Reload Example

import app from './app'; // configuring express app, e.g. routes and logic

function startServer() {
  return new Promise((resolve, reject) => {
    const httpServer = app.listen(app.get('port'));

    httpServer.once('error', (err: any) => {
      if (err.code === 'EADDRINUSE') {
        reject(err);
      }
    });

    httpServer.once('listening', () => resolve(httpServer));
  }).then((httpServer) => {
    const { port } = httpServer.address();
    console.info(`==> 🌎 Listening on ${port}. Open up http://localhost:${port}/ in your browser.`);

    // Hot Module Replacement API
    if (module.hot) {
      let currentApp = app;
      module.hot.accept('./app', () => {
        httpServer.removeListener('request', currentApp);
        import('./app')
          .then(({ default: nextApp }) => {
            currentApp = nextApp;
            httpServer.on('request', currentApp);
            console.log('HttpServer reloaded!');
          })
          .catch((err) => console.error(err));
      });

      // For reload main module (self). It will be restart http-server.
      module.hot.accept((err) => console.error(err));
      module.hot.dispose(() => {
        console.log('Disposing entry module...');
        httpServer.close();
      });
    }
  });
}

console.log('Starting http server...');
startServer().catch((err) => {
  console.error('Error in server start script.', err);
});

Troubleshooting

Running Node Hot Loader inside a Docker container

If you attempt to run the Node Hot Loader inside a Docker container, it will start and serve as expected, but will not Hot Module Reload without some additional configuration. Add the following to your webpack config:

module.exports = {
  //...
  watchOptions: {
    poll: 1000, // Check for changes every second
  },
};

This instructs webpack to poll for changes (every second) instead of watching. This is necessary because watching does not work with NFS and machines in VirtualBox. See Webpack Configuration docs for more information.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].