-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathconfig-overrides.js
More file actions
67 lines (59 loc) · 1.96 KB
/
config-overrides.js
File metadata and controls
67 lines (59 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
module.exports = {
webpack: function override(config) {
config.plugins.push(
new NodePolyfillPlugin({
excludeAliases: ["console"],
})
);
return config;
},
devServer: function overrideDevServer(configFn) {
return function (proxy, allowedHost) {
// Shim CRA's expected devServer.close() on webpack-dev-server v5 instances
try {
const WebpackDevServer = require("webpack-dev-server");
if (
WebpackDevServer &&
WebpackDevServer.prototype &&
typeof WebpackDevServer.prototype.stop === "function" &&
typeof WebpackDevServer.prototype.close !== "function"
) {
WebpackDevServer.prototype.close = WebpackDevServer.prototype.stop;
}
} catch (e) {
// no-op if require fails
}
const config = configFn(proxy, allowedHost);
// Remove deprecated v4 hooks rejected by wds v5 schema
if (config.onBeforeSetupMiddleware) {
delete config.onBeforeSetupMiddleware;
}
if (config.onAfterSetupMiddleware) {
delete config.onAfterSetupMiddleware;
}
// Migrate deprecated `https`/`http2` to webpack-dev-server v5 `server` option
if (Object.prototype.hasOwnProperty.call(config, "https")) {
const httpsOption = config.https;
if (httpsOption) {
if (typeof httpsOption === "object") {
config.server = { type: "https", options: httpsOption };
} else {
config.server = "https";
}
} else {
config.server = "http";
}
delete config.https;
}
if (Object.prototype.hasOwnProperty.call(config, "http2")) {
delete config.http2;
}
// Ensure setupMiddlewares exists for wds v5
if (!config.setupMiddlewares) {
config.setupMiddlewares = (middlewares) => middlewares;
}
return config;
};
},
};