All Projects → webpack-contrib → Webpack Hot Client

webpack-contrib / Webpack Hot Client

Licence: mit
webpack HMR Client

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Webpack Hot Client

Postcss Variables Loader
Share variables between CSS and JS with Webpack + HMR
Stars: ✭ 18 (-84.48%)
Mutual labels:  webpack, hmr
Laravel Blog
Laravel 8.0 blog application with Vue.js, Homestead, Horizon, Telescope and Pusher
Stars: ✭ 1,248 (+975.86%)
Mutual labels:  webpack, websockets
Pyramidvue
Pyramid Web Framework (Python) implemented with Vuejs (JavaScript) & Webpack (HMR): starter template
Stars: ✭ 32 (-72.41%)
Mutual labels:  webpack, hmr
Generator Ng Fullstack
Client, server or fullstack - it's up to you. ng-fullstack gives you the best of the latest.
Stars: ✭ 701 (+504.31%)
Mutual labels:  webpack, client
Ts React Boilerplate
Universal React App with Redux 4, Typescript 3, and Webpack 4
Stars: ✭ 104 (-10.34%)
Mutual labels:  webpack, hmr
Spring Streaming
SPA on Spring Boot 1.x, WebSockets and React, gradle, nodejs, spring-boot, gradle multi project, spring-mvc, spring-data, gradle dependency update plugin, react-router
Stars: ✭ 6 (-94.83%)
Mutual labels:  webpack, websockets
Megalodon
Mastodon, Pleroma and Misskey API client library for node.js and browser
Stars: ✭ 52 (-55.17%)
Mutual labels:  websockets, client
React Study
渐进式学习React生态圈
Stars: ✭ 548 (+372.41%)
Mutual labels:  webpack, hmr
Webpack Core Usage
webpack2完整系列课程,欢迎阅读。同时欢迎移步我的react全家桶文章全集: https://github.com/liangklfangl/react-article-bucket
Stars: ✭ 94 (-18.97%)
Mutual labels:  webpack, hmr
Cookiecutter Webpack
Boilerplate for webpack 2, babel, react + redux + hmr, and karma. Can be inserted into existing django projects.
Stars: ✭ 87 (-25%)
Mutual labels:  webpack, hmr
React Ssr Setup
React Starter Project with Webpack 4, Babel 7, TypeScript, CSS Modules, Server Side Rendering, i18n and some more niceties
Stars: ✭ 678 (+484.48%)
Mutual labels:  webpack, hmr
Sass Vars Loader
Use Sass variables defined in Webpack config or in external Javascript or JSON files
Stars: ✭ 112 (-3.45%)
Mutual labels:  webpack, hmr
Universal
Seed project for Angular Universal apps featuring Server-Side Rendering (SSR), Webpack, CLI scaffolding, dev/prod modes, AoT compilation, HMR, SCSS compilation, lazy loading, config, cache, i18n, SEO, and TSLint/codelyzer
Stars: ✭ 669 (+476.72%)
Mutual labels:  webpack, hmr
Cypress Hmr Restarter
A Cypress plugin which restarts tests on webpack-dev-server HMR updates
Stars: ✭ 18 (-84.48%)
Mutual labels:  webpack, hmr
React Webpack Typescript Starter
Minimal starter with hot module replacement (HMR) for rapid development.
Stars: ✭ 632 (+444.83%)
Mutual labels:  webpack, hmr
Webpack Webextension Plugin
Webpack plugin that compiles WebExtension manifest.json files and adds smart auto reload
Stars: ✭ 47 (-59.48%)
Mutual labels:  webpack, websockets
Angular Hmr
🔥 Angular Hot Module Replacement for Hot Module Reloading
Stars: ✭ 490 (+322.41%)
Mutual labels:  webpack, hmr
Angularwebpackvisualstudio
Template for ASP.NET Core, Angular with Webpack and Visual Studio
Stars: ✭ 497 (+328.45%)
Mutual labels:  webpack, hmr
React Dashboard
🔥React Dashboard - isomorphic admin dashboard template (React.js, Bootstrap, Node.js, GraphQL, React Router, Babel, Webpack, Browsersync) 🔥
Stars: ✭ 1,268 (+993.1%)
Mutual labels:  webpack, hmr
Node Hot Loader
Hot module replacement (hot reload) for Node.js applications. Develop without server restarting.
Stars: ✭ 111 (-4.31%)
Mutual labels:  webpack, hmr

npm node deps tests chat size

webpack-hot-client

A client for enabling, and interacting with, webpack Hot Module Replacement.

This is intended to work in concert with webpack-dev-middleware and allows for adding Hot Module Replacement to an existing server, without a dependency upon webpack-dev-server. This comes in handy for testing in projects that already use server frameworks such as Express or Koa.

webpack-hot-client accomplishes this by creating a WebSocket server, providing the necessary client (browser) scripts that communicate via WebSockets, and automagically adding the necessary webpack plugins and config entries. All of that allows for a seamless integration of Hot Module Replacement Support.

Curious about the differences between this module and webpack-hot-middleware? Read more here.

Requirements

This module requires a minimum of Node v6.9.0 and Webpack v4.0.0.

Getting Started

To begin, you'll need to install webpack-hot-client:

$ npm install webpack-hot-client --save-dev

Gotchas

Entries

In order to use webpack-hot-client, your webpack config should include an entry option that is set to an Array of String, or an Object who's keys are set to an Array of String. You may also use a Function, but that function should return a value in one of the two valid formats.

This is primarily due to restrictions in webpack itself and the way that it processes options and entries. For users of webpack v4+ that go the zero-config route, you must specify an entry option.

Automagical Configuration

As a convenience webpack-hot-client adds HotModuleReplacementPlugin and the necessary entries to your webpack config for you at runtime. Including the plugin in your config manually while using this module may produce unexpected or wonky results. If you have a need to configure entries and plugins for HMR manually, use the autoConfigure option.

Best Practices

When using this module manually, along with the default port option value of 0, starting compilation (or passing a compiler to webpack-dev-middleware) should be done after the socket server has finished listening and allocating a port. This ensures that the build will contain the allocated port. (See the Express example below.) This condition does not apply if providing a static port option to the API.

Express

For setting up the module for use with an Express server, try the following:

const hotClient = require('webpack-hot-client');
const middleware = require('webpack-dev-middleware');
const webpack = require('webpack');
const config = require('./webpack.config');

const compiler = webpack(config);
const { publicPath } = config.output;
const options = { ... }; // webpack-hot-client options

// we recommend calling the client _before_ adding the dev middleware
const client = hotClient(compiler, options);
const { server } = client;

server.on('listening', () => {
  app.use(middleware(compiler, { publicPath }));
});

Koa

Since Koa@2.0.0 was released, the patterns and requirements for using webpack-dev-middleware have changed somewhat, due to use of async/await in Koa. As such, one potential solution is to use koa-webpack, which wires up the dev middleware properly for Koa, and also implements this module. If you'd like to use both modules without koa-webpack, you may examine that module's code for implementation details.

Browser Support

Because this module leverages native WebSockets, the browser support for this module is limited to only those browsers which support native WebSocket. That typically means the last two major versions of a particular browser.

Please visit caniuse.com for a full compatibility table.

Note: We won't be accepting requests for changes to this facet of the module.

API

client(compiler, [options])

Returns an Object containing:

  • close() (Function) - Closes the WebSocketServer started by the module.
  • wss (WebSocketServer) - A WebSocketServer instance.

options

Type: Object

allEntries

Type: Boolean
Default: false

If true and autoConfigure is true, will automatically configures each entry key for the webpack compiler. Typically used when working with or manipulating different chunks in the same compiler configuration.

autoConfigure

Type: Boolean
Default: true

If true, automatically configures the entry for the webpack compiler, and adds the HotModuleReplacementPlugin to the compiler.

host

Type: String|Object
Default: 'localhost'

Sets the host that the WebSocket server will listen on. If this doesn't match the host of the server the module is used with, the module may not function properly. If the server option is defined, and the server has been instructed to listen, this option is ignored.

If using the module in a specialized environment, you may choose to specify an object to define client and server host separately. The object value should match { client: <String>, server: <String> }. Be aware that the client host will be used in the browser by WebSockets. You should not use this option in this way unless you know what you're doing. Using a mismatched client and server host will be unsupported by the project as the behavior in the browser can be unpredictable and is specific to a particular environment.

The value of host.client can also be set to a wildcard character for Remote Machine Testing.

hmr

Type: Boolean
Default: true

If true, instructs the client script to attempt Hot Module Replacement patching of modules.

https

Type: Boolean
Default: false

If true, instructs the client script to use wss:// as the WebSocket protocol.

When using the server option and passing an instance of https.Server, this flag must also be true. Otherwise, the sockets cannot communicate and this module won't function properly. The module will examine the server instance passed and if server is an instance of https.Server, and https is not already set, will set https to true.

Note: When using a self-signed certificate on Firefox, you must add a "Server Exception" for localhost:{port} where {port} is either the port or the port.server option for secure WebSocket to work correctly.

logLevel

Type: String
Default: 'info'

Sets the minimum level of logs that will be displayed in the console. Please see webpack-log/#levels for valid values.

logTime

Type: Boolean
Default: false

If true, instructs the internal logger to prepend log output with a timestamp.

port

Type: Number|Object
Default: 0

The port the WebSocket server should listen on. By default, the socket server will allocate a port. If a different port is chosen, the consumer of the module must ensure that the port is free before hand. If the server option is defined, and the server has been instructed to listen, this option is ignored.

If using the module in a specialized environment, you may choose to specify an object to define client and server port separately. The object value should match { client: <Number>, server: <Number> }. Be aware that the client port will be used in the browser by WebSockets. You should not use this option in this way unless you know what you're doing. Using a mismatched client and server port will be unsupported by the project as the behavior in the browser can be unpredictable and is specific to a particular environment.

reload

Type: Boolean
Default: true

If true, instructs the browser to physically refresh the entire page if / when webpack indicates that a hot patch cannot be applied and a full refresh is needed.

This option also instructs the browser whether or not to refresh the entire page when hmr: false is used.

Note: If both hmr and reload are false, and these are permanent settings, it makes this module fairly useless.

server

Type: Object
Default: null

If a server instance (eg. Express or Koa) is provided, the WebSocket server will attempt to attach to the server instance instead of using a separate port.

stats

Type: Object
Default: { context: process.cwd() }

An object specifying the webpack stats configuration. This does not typically need to be modified.

validTargets

Type: Array[String] Default: ['web']

By default, webpack-hot-client is meant to, and expects to function on the 'web' build target. However, you can manipulate this by adding targets to this property. eg.

  // will be merged with the default 'web' target
  validTargets: ['batmobile']

Communicating with Client WebSockets

Please see the WebSockets documentation.

Remote Machine Testing

Please see the Remote Machine Testing documentation.

Contributing

We welcome your contributions! Please have a read of CONTRIBUTING for more information on how to get involved.

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].