Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions packages/react-scripts/config/webpackDevServer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,37 +99,45 @@ module.exports = function (proxy, allowedHost) {
publicPath: paths.publicUrlOrPath.slice(0, -1),
},

https: getHttpsConfig(),
// webpack-dev-server v5 replaced the top-level `https` option with `server`.
// getHttpsConfig() returns false, true, or { cert, key }.
server: (() => {
const httpsConfig = getHttpsConfig();
if (!httpsConfig) return 'http';
if (httpsConfig === true) return 'https';
return { type: 'https', options: httpsConfig };
})(),
host,
historyApiFallback: {
// Paths with dots should still use the history fallback.
// See https://github.com/facebook/create-react-app/issues/387.
disableDotRule: true,
index: paths.publicUrlOrPath,
},
// `proxy` is run between `before` and `after` `webpack-dev-server` hooks
proxy,
onBeforeSetupMiddleware(devServer) {
// webpack-dev-server v5 replaced onBeforeSetupMiddleware/onAfterSetupMiddleware with setupMiddlewares.
setupMiddlewares(middlewares, devServer) {
Comment thread
mholwill marked this conversation as resolved.
// Keep `evalSourceMapMiddleware`
// middlewares before `redirectServedPath` otherwise will not have any effect
// This lets us fetch source contents from webpack for the error overlay
devServer.app.use(evalSourceMapMiddleware(devServer));
middlewares.unshift(evalSourceMapMiddleware(devServer));
Comment thread
mholwill marked this conversation as resolved.

if (fs.existsSync(paths.proxySetup)) {
// This registers user provided middleware for proxy reasons
require(paths.proxySetup)(devServer.app);
}
},
onAfterSetupMiddleware(devServer) {

// Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match
devServer.app.use(redirectServedPath(paths.publicUrlOrPath));
middlewares.push(redirectServedPath(paths.publicUrlOrPath));
Comment thread
mholwill marked this conversation as resolved.

// This service worker file is effectively a 'no-op' that will reset any
// previous service worker registered for the same host:port combination.
// We do this in development to avoid hitting the production cache if
// it used the same host and port.
// https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
devServer.app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath));
middlewares.push(noopServiceWorkerMiddleware(paths.publicUrlOrPath));

return middlewares;
Comment thread
mholwill marked this conversation as resolved.
},
};
};
Loading