File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ class Bundler extends EventEmitter {
7878 minify :
7979 typeof options . minify === 'boolean' ? options . minify : isProduction ,
8080 hmr : typeof options . hmr === 'boolean' ? options . hmr : watch ,
81+ https : options . https || false ,
8182 logLevel : typeof options . logLevel === 'number' ? options . logLevel : 3 ,
8283 mainFile : this . mainFile ,
8384 hmrPort : options . hmrPort || 0 ,
@@ -248,7 +249,7 @@ class Bundler extends EventEmitter {
248249
249250 if ( this . options . hmr ) {
250251 this . hmr = new HMRServer ( ) ;
251- this . options . hmrPort = await this . hmr . start ( this . options . hmrPort ) ;
252+ this . options . hmrPort = await this . hmr . start ( this . options ) ;
252253 }
253254
254255 this . farm = WorkerFarm . getShared ( this . options ) ;
Original file line number Diff line number Diff line change 1+ const http = require ( 'http' ) ;
2+ const https = require ( 'https' ) ;
13const WebSocket = require ( 'ws' ) ;
24const prettyError = require ( './utils/prettyError' ) ;
5+ const generateCertificate = require ( './utils/generateCertificate' ) ;
36const logger = require ( './Logger' ) ;
47
58class HMRServer {
6- async start ( port ) {
9+ async start ( options = { } ) {
710 await new Promise ( resolve => {
8- this . wss = new WebSocket . Server ( { port} , resolve ) ;
11+ let server = options . https
12+ ? https . createServer ( generateCertificate ( options ) )
13+ : http . createServer ( ) ;
14+
15+ this . wss = new WebSocket . Server ( { server} ) ;
16+ server . listen ( options . hmrPort , resolve ) ;
917 } ) ;
1018
1119 this . wss . on ( 'connection' , ws => {
Original file line number Diff line number Diff line change @@ -16,7 +16,8 @@ module.bundle.Module = Module;
1616
1717if ( ! module . bundle . parent && typeof WebSocket !== 'undefined' ) {
1818 var hostname = process . env . HMR_HOSTNAME || location . hostname ;
19- var ws = new WebSocket ( 'ws://' + hostname + ':' + process . env . HMR_PORT + '/' ) ;
19+ var protocol = window . location . protocol === 'https:' ? 'wss' : 'ws' ;
20+ var ws = new WebSocket ( protocol + '://' + hostname + ':' + process . env . HMR_PORT + '/' ) ;
2021 ws . onmessage = function ( event ) {
2122 var data = JSON . parse ( event . data ) ;
2223
You can’t perform that action at this time.
0 commit comments