2
2
3
3
const path = require ( 'path' ) ;
4
4
const url = require ( 'url' ) ;
5
- const http = require ( 'http' ) ;
6
- const https = require ( 'https' ) ;
7
5
const fs = require ( 'graceful-fs' ) ;
8
6
const ipaddr = require ( 'ipaddr.js' ) ;
9
7
const internalIp = require ( 'internal-ip' ) ;
10
8
const killable = require ( 'killable' ) ;
11
- const chokidar = require ( 'chokidar' ) ;
12
9
const express = require ( 'express' ) ;
13
- const { createProxyMiddleware } = require ( 'http-proxy-middleware' ) ;
14
- const historyApiFallback = require ( 'connect-history-api-fallback' ) ;
15
- const compress = require ( 'compression' ) ;
16
- const serveIndex = require ( 'serve-index' ) ;
17
- const webpack = require ( 'webpack' ) ;
18
- const webpackDevMiddleware = require ( 'webpack-dev-middleware' ) ;
19
- const getFilenameFromUrl =
20
- require ( 'webpack-dev-middleware/dist/utils/getFilenameFromUrl' ) . default ;
21
10
const { validate } = require ( 'schema-utils' ) ;
22
- const DevServerPlugin = require ( './utils/DevServerPlugin' ) ;
23
11
const normalizeOptions = require ( './utils/normalizeOptions' ) ;
24
- const getCertificate = require ( './utils/getCertificate' ) ;
25
12
const colors = require ( './utils/colors' ) ;
26
- const runOpen = require ( './utils/runOpen' ) ;
27
- const runBonjour = require ( './utils/runBonjour' ) ;
28
13
const routes = require ( './utils/routes' ) ;
29
14
const getSocketServerImplementation = require ( './utils/getSocketServerImplementation' ) ;
30
15
const getCompilerConfigArray = require ( './utils/getCompilerConfigArray' ) ;
31
- const getStatsOption = require ( './utils/getStatsOption' ) ;
32
- const getColorsOption = require ( './utils/getColorsOption' ) ;
33
16
const setupExitSignals = require ( './utils/setupExitSignals' ) ;
34
- const findPort = require ( './utils/findPort' ) ;
35
17
const schema = require ( './options.json' ) ;
36
18
37
19
if ( ! process . env . WEBPACK_SERVE ) {
@@ -93,6 +75,8 @@ class Server {
93
75
}
94
76
95
77
applyDevServerPlugin ( ) {
78
+ const DevServerPlugin = require ( './utils/DevServerPlugin' ) ;
79
+
96
80
const compilers = this . compiler . compilers || [ this . compiler ] ;
97
81
98
82
// eslint-disable-next-line no-shadow
@@ -102,7 +86,9 @@ class Server {
102
86
}
103
87
104
88
setupProgressPlugin ( ) {
105
- new webpack . ProgressPlugin ( ( percent , msg , addInfo ) => {
89
+ const { ProgressPlugin } = require ( 'webpack' ) ;
90
+
91
+ new ProgressPlugin ( ( percent , msg , addInfo ) => {
106
92
percent = Math . floor ( percent * 100 ) ;
107
93
108
94
if ( percent === 100 ) {
@@ -162,6 +148,8 @@ class Server {
162
148
}
163
149
164
150
setupDevMiddleware ( ) {
151
+ const webpackDevMiddleware = require ( 'webpack-dev-middleware' ) ;
152
+
165
153
// middleware for serving webpack bundle
166
154
this . middleware = webpackDevMiddleware (
167
155
this . compiler ,
@@ -170,10 +158,14 @@ class Server {
170
158
}
171
159
172
160
setupCompressFeature ( ) {
161
+ const compress = require ( 'compression' ) ;
162
+
173
163
this . app . use ( compress ( ) ) ;
174
164
}
175
165
176
166
setupProxyFeature ( ) {
167
+ const { createProxyMiddleware } = require ( 'http-proxy-middleware' ) ;
168
+
177
169
/**
178
170
* Assume a proxy configuration specified as:
179
171
* proxy: {
@@ -319,6 +311,8 @@ class Server {
319
311
}
320
312
321
313
setupHistoryApiFallbackFeature ( ) {
314
+ const historyApiFallback = require ( 'connect-history-api-fallback' ) ;
315
+
322
316
const fallback =
323
317
typeof this . options . historyApiFallback === 'object'
324
318
? this . options . historyApiFallback
@@ -340,6 +334,8 @@ class Server {
340
334
}
341
335
342
336
setupStaticServeIndexFeature ( ) {
337
+ const serveIndex = require ( 'serve-index' ) ;
338
+
343
339
this . options . static . forEach ( ( staticOption ) => {
344
340
staticOption . publicPath . forEach ( ( publicPath ) => {
345
341
if ( staticOption . serveIndex ) {
@@ -514,6 +510,8 @@ class Server {
514
510
}
515
511
516
512
if ( this . options . https ) {
513
+ const getCertificate = require ( './utils/getCertificate' ) ;
514
+
517
515
for ( const property of [ 'cacert' , 'pfx' , 'key' , 'cert' ] ) {
518
516
const value = this . options . https [ property ] ;
519
517
const isBuffer = value instanceof Buffer ;
@@ -546,6 +544,9 @@ class Server {
546
544
}
547
545
548
546
createServer ( ) {
547
+ const https = require ( 'https' ) ;
548
+ const http = require ( 'http' ) ;
549
+
549
550
if ( this . options . https ) {
550
551
if ( this . options . http2 ) {
551
552
// TODO: we need to replace spdy with http2 which is an internal module
@@ -628,6 +629,8 @@ class Server {
628
629
}
629
630
630
631
showStatus ( ) {
632
+ const getColorsOption = require ( './utils/getColorsOption' ) ;
633
+
631
634
const useColor = getColorsOption ( getCompilerConfigArray ( this . compiler ) ) ;
632
635
const protocol = this . options . https ? 'https' : 'http' ;
633
636
const { address, port } = this . server . address ( ) ;
@@ -749,13 +752,17 @@ class Server {
749
752
}
750
753
751
754
if ( this . options . open ) {
755
+ const runOpen = require ( './utils/runOpen' ) ;
756
+
752
757
const openTarget = prettyPrintUrl ( this . hostname || 'localhost' ) ;
753
758
754
759
runOpen ( openTarget , this . options . open , this . logger ) ;
755
760
}
756
761
}
757
762
758
763
listen ( port , hostname , fn ) {
764
+ const findPort = require ( './utils/findPort' ) ;
765
+
759
766
if ( hostname === 'local-ip' ) {
760
767
this . hostname = internalIp . v4 . sync ( ) || internalIp . v6 . sync ( ) || '0.0.0.0' ;
761
768
} else if ( hostname === 'local-ipv4' ) {
@@ -784,6 +791,8 @@ class Server {
784
791
}
785
792
786
793
if ( this . options . bonjour ) {
794
+ const runBonjour = require ( './utils/runBonjour' ) ;
795
+
787
796
runBonjour ( this . options ) ;
788
797
}
789
798
@@ -838,6 +847,8 @@ class Server {
838
847
}
839
848
840
849
getStats ( statsObj ) {
850
+ const getStatsOption = require ( './utils/getStatsOption' ) ;
851
+
841
852
const stats = Server . DEFAULT_STATS ;
842
853
843
854
const configArr = getCompilerConfigArray ( this . compiler ) ;
@@ -974,6 +985,9 @@ class Server {
974
985
}
975
986
976
987
serveMagicHtml ( req , res , next ) {
988
+ const getFilenameFromUrl =
989
+ require ( 'webpack-dev-middleware/dist/utils/getFilenameFromUrl' ) . default ;
990
+
977
991
const _path = req . path ;
978
992
979
993
try {
@@ -1050,6 +1064,8 @@ class Server {
1050
1064
interval,
1051
1065
} ;
1052
1066
1067
+ const chokidar = require ( 'chokidar' ) ;
1068
+
1053
1069
const watcher = chokidar . watch ( watchPath , finalWatchOptions ) ;
1054
1070
1055
1071
// disabling refreshing on changing the content
0 commit comments