-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathwebpack.dev.mjs
More file actions
55 lines (49 loc) · 1.4 KB
/
webpack.dev.mjs
File metadata and controls
55 lines (49 loc) · 1.4 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
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin";
import detectPort from "detect-port";
import { merge } from "webpack-merge";
import commonConfig from "./webpack.common.mjs";
const DEFAULT_PORT = 3000;
const COLORS = {
reset: "\x1b[0m",
yellow: "\x1b[33m",
};
async function getAvailablePort() {
const availablePort = await detectPort(DEFAULT_PORT);
if (availablePort !== DEFAULT_PORT) {
console.log(
`${COLORS.yellow}⚠️ Port ${DEFAULT_PORT} is occupied. Using available port ${availablePort} instead.${COLORS.reset}`,
);
}
return availablePort;
}
const devConfig = async () => {
const availablePort = await getAvailablePort();
return merge(commonConfig, {
mode: "development",
devtool: "eval-cheap-module-source-map",
devServer: {
historyApiFallback: true,
hot: true,
liveReload: false,
port: availablePort,
client: { overlay: false },
headers: {
"Cross-Origin-Embedder-Policy": "credentialless",
"Cross-Origin-Opener-Policy": "same-origin",
},
setupExitSignals: true,
},
watchOptions: {
ignored: /node_modules/,
aggregateTimeout: 300,
poll: 1000,
},
optimization: {
removeAvailableModules: false,
removeEmptyChunks: false,
splitChunks: false,
},
plugins: [new ReactRefreshWebpackPlugin()],
});
};
export default devConfig;