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
9
const express = require ( 'express' ) ;
12
- const compress = require ( 'compression' ) ;
13
- const serveIndex = require ( 'serve-index' ) ;
14
- const webpack = require ( 'webpack' ) ;
15
- const webpackDevMiddleware = require ( 'webpack-dev-middleware' ) ;
16
10
const getFilenameFromUrl =
17
11
require ( 'webpack-dev-middleware/dist/utils/getFilenameFromUrl' ) . default ;
18
12
const { validate } = require ( 'schema-utils' ) ;
@@ -99,7 +93,9 @@ class Server {
99
93
}
100
94
101
95
setupProgressPlugin ( ) {
102
- new webpack . ProgressPlugin ( ( percent , msg , addInfo ) => {
96
+ const { ProgressPlugin } = require ( 'webpack' ) ;
97
+
98
+ new ProgressPlugin ( ( percent , msg , addInfo ) => {
103
99
percent = Math . floor ( percent * 100 ) ;
104
100
105
101
if ( percent === 100 ) {
@@ -159,6 +155,8 @@ class Server {
159
155
}
160
156
161
157
setupDevMiddleware ( ) {
158
+ const webpackDevMiddleware = require ( 'webpack-dev-middleware' ) ;
159
+
162
160
// middleware for serving webpack bundle
163
161
this . middleware = webpackDevMiddleware (
164
162
this . compiler ,
@@ -167,6 +165,8 @@ class Server {
167
165
}
168
166
169
167
setupCompressFeature ( ) {
168
+ const compress = require ( 'compression' ) ;
169
+
170
170
this . app . use ( compress ( ) ) ;
171
171
}
172
172
@@ -344,6 +344,8 @@ class Server {
344
344
this . options . static . forEach ( ( staticOption ) => {
345
345
staticOption . publicPath . forEach ( ( publicPath ) => {
346
346
if ( staticOption . serveIndex ) {
347
+ const serveIndex = require ( 'serve-index' ) ;
348
+
347
349
this . app . use ( publicPath , ( req , res , next ) => {
348
350
// serve-index doesn't fallthrough non-get/head request to next middleware
349
351
if ( req . method !== 'GET' && req . method !== 'HEAD' ) {
@@ -560,9 +562,13 @@ class Server {
560
562
this . app
561
563
) ;
562
564
} else {
565
+ const https = require ( 'https' ) ;
566
+
563
567
this . server = https . createServer ( this . options . https , this . app ) ;
564
568
}
565
569
} else {
570
+ const http = require ( 'http' ) ;
571
+
566
572
this . server = http . createServer ( this . app ) ;
567
573
}
568
574
0 commit comments