11import * as path from "path" ;
22import * as express from "express" ;
3+ import * as webpack from "webpack" ;
34import * as bodyParser from "body-parser" ;
45import * as serveStatic from "serve-static" ;
56import * as queryString from "querystring" ;
@@ -8,9 +9,11 @@ import * as http from "http";
89import * as https from "https" ;
910import { URL } from "url" ;
1011import * as UrlPattern from "url-pattern" ;
12+ // @ts -ignore
1113import * as getPort from "get-port" ;
1214// @ts -ignore
1315import * as expressHttpProxy from "express-http-proxy" ;
16+ import * as webpackHotMiddleware from "webpack-hot-middleware" ;
1417
1518import { Logger } from "../helper" ;
1619import { Netlify } from "../netlify" ;
@@ -185,6 +188,10 @@ export class Server {
185188 this . express . use ( bodyParser . raw ( { limit : "6mb" } ) ) ;
186189 this . express . use ( bodyParser . text ( { limit : "6mb" , type : "*/*" } ) ) ;
187190
191+ if ( this . options . netlifyConfig . plugins . local . webpack . hmr ) {
192+ this . webpackHotMiddleware ( this . options . compilers ) ;
193+ }
194+
188195 const hardRedirects = this . options . netlifyConfig . redirects . filter ( ( redirect ) => redirect . force === true ) ;
189196 const softRedirects = this . options . netlifyConfig . redirects . filter ( ( redirect ) => redirect . force === false ) ;
190197
@@ -195,6 +202,14 @@ export class Server {
195202 this . routeRedirects ( softRedirects ) ;
196203 }
197204
205+ public webpackHotMiddleware ( compilers : Array < webpack . Compiler > ) : void {
206+ const clientCompiler = compilers . find ( compiler => compiler . name === "client" ) ;
207+ const clientMiddleware = webpackHotMiddleware ( clientCompiler , {
208+ log : false ,
209+ } ) ;
210+ this . express . use ( clientMiddleware ) ;
211+ }
212+
198213 /**
199214 * Static Router
200215 */
@@ -343,6 +358,7 @@ export namespace Server {
343358 export interface Options {
344359 netlifyConfig : Netlify . Config ;
345360 findAvailablePort ?: boolean ;
361+ compilers ?: Array < webpack . Compiler > ;
346362 }
347363 export interface Certificates {
348364 key : string ;
0 commit comments