@@ -15,55 +15,22 @@ const sockPort = process.env.WDS_SOCKET_PORT;
1515module . exports = function ( proxy , _allowedHost ) {
1616 return {
1717 allowedHosts : "all" ,
18- // Enable gzip compression of generated files.
1918 compress : true ,
20- // Enable hot reloading server. It will provide WDS_SOCKET_PATH endpoint
21- // for the WebpackDevServer client so it can learn when the files were
22- // updated. The WebpackDevServer client is included as an entry point
23- // in the webpack development configuration. Note that only changes
24- // to CSS are currently hot reloaded. JS changes will refresh the browser.
2519 hot : true ,
26- // Use 'ws' instead of 'sockjs-node' on server since we're using native
27- // websockets in `webpackHotDevClient`.
2820 webSocketServer : "ws" ,
29- // It is important to tell WebpackDevServer to use the same "publicPath" path as
30- // we specified in the webpack config. When homepage is '.', default to serving
31- // from the root.
32- // remove last slash so user can land on `/test` instead of `/test/`
3321 devMiddleware : {
3422 publicPath : paths . publicUrlOrPath . slice ( 0 , - 1 ) ,
3523 } ,
3624 static : {
37- // By default WebpackDevServer serves physical files from current directory
38- // in addition to all the virtual build products that it serves from memory.
39- // This is confusing because those files won’t automatically be available in
40- // production build folder unless we copy them. However, copying the whole
41- // project directory is dangerous because we may expose sensitive files.
42- // Instead, we establish a convention that only files in `public` directory
43- // get served. Our build script will copy `public` into the `build` folder.
44- // In `index.html`, you can get URL of `public` folder with %PUBLIC_URL%:
45- // <link rel="icon" href="%PUBLIC_URL%/favicon.ico">
46- // In JavaScript code, you can access it with `process.env.PUBLIC_URL`.
47- // Note that we only recommend to use `public` folder as an escape hatch
48- // for files like `favicon.ico`, `manifest.json`, and libraries that are
49- // for some reason broken when imported through webpack. If you just want to
50- // use an image, put it in `src` and `import` it from JavaScript instead.
5125 directory : paths . appPublic ,
5226 publicPath : paths . publicUrlOrPath ,
53- // By default files from `directory` will not trigger a page reload.
54- // Reportedly, this avoids CPU overload on some systems.
55- // https://github.com/facebook/create-react-app/issues/293
56- // src/node_modules is not ignored to support absolute imports
57- // https://github.com/facebook/create-react-app/issues/1065
5827 watch : {
5928 ignored : ignoredFiles ( paths . appSrc ) ,
6029 } ,
6130 } ,
6231 https : getHttpsConfig ( ) ,
6332 host,
6433 historyApiFallback : {
65- // Paths with dots should still use the history fallback.
66- // See https://github.com/facebook/create-react-app/issues/387.
6734 disableDotRule : true ,
6835 index : paths . publicUrlOrPath ,
6936 } ,
@@ -76,44 +43,39 @@ module.exports = function (proxy, _allowedHost) {
7643 "Cross-Origin-Embedder-Policy" : "require-corp" ,
7744 } ,
7845 client : {
79- // Silence WebpackDevServer's own logs since they're generally not useful.
80- // It will still show compile warnings and errors with this setting.
8146 logging : "none" ,
8247 overlay : false ,
8348 webSocketURL : {
84- // Enable custom sockjs pathname for websocket connection to hot reloading server.
85- // Enable custom sockjs hostname, pathname and port for websocket connection
86- // to hot reloading server.
8749 hostname : sockHost ,
8850 pathname : sockPath ,
8951 port : sockPort ,
9052 } ,
9153 } ,
92- // `proxy` is run between `before` and `after` `webpack-dev-server` hooks
9354 proxy,
94- onBeforeSetupMiddleware ( devServer ) {
55+ setupMiddlewares : ( middlewares , devServer ) => {
9556 // Keep `evalSourceMapMiddleware` and `errorOverlayMiddleware`
9657 // middlewares before `redirectServedPath` otherwise will not have any effect
9758 // This lets us fetch source contents from webpack for the error overlay
98- devServer . app . use ( evalSourceMapMiddleware ( devServer ) ) ;
59+ middlewares . unshift ( evalSourceMapMiddleware ( devServer ) ) ;
9960 // This lets us open files from the runtime error overlay.
100- devServer . app . use ( errorOverlayMiddleware ( ) ) ;
61+ middlewares . unshift ( errorOverlayMiddleware ( ) ) ;
10162
10263 if ( fs . existsSync ( paths . proxySetup ) ) {
10364 // This registers user provided middleware for proxy reasons
10465 require ( paths . proxySetup ) ( devServer . app ) ;
10566 }
106- } ,
107- onAfterSetupMiddleware ( devServer ) {
67+
10868 // Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match
109- devServer . app . use ( redirectServedPath ( paths . publicUrlOrPath ) ) ;
69+ middlewares . push ( redirectServedPath ( paths . publicUrlOrPath ) ) ;
11070
11171 // This service worker file is effectively a 'no-op' that will reset any
11272 // previous service worker registered for the same host:port combination.
11373 // We do this in development to avoid hitting the production cache if
11474 // it used the same host and port.
11575 // https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
116- devServer . app . use ( noopServiceWorkerMiddleware ( paths . publicUrlOrPath ) ) ;
76+ middlewares . push ( noopServiceWorkerMiddleware ( paths . publicUrlOrPath ) ) ;
77+
78+ return middlewares ;
11779 } ,
11880 } ;
11981} ;
0 commit comments