-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.dev.js
58 lines (55 loc) · 1.55 KB
/
webpack.dev.js
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
const path = require("path");
const { merge } = require("webpack-merge");
const commonConfig = require("./webpack.common");
const webpack = require("webpack");
const InterpolateHtmlPlugin = require("interpolate-html-plugin");
require("dotenv").config({ path: "./.env.development" });
const devConfig = (env) => {
const watch = env?.watch || false;
const port = env?.port || process.env.PORT;
return {
devtool: "inline-cheap-source-map",
entry: path.join(__dirname, "src", "index.tsx"),
target: "web",
mode: "development",
devServer: {
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Headers": "*",
},
watchFiles: watch ? ["./src/*"] : undefined,
liveReload: watch,
hot: false,
open: watch,
historyApiFallback: true,
// static: {
// directory: path.join(__dirname, "public"),
// },
client: {
overlay: {
errors: true,
warnings: true,
},
reconnect: 5,
},
compress: true,
port: process.env.PORT,
},
resolve: {
modules: [path.join(__dirname, "src"), "node_modules"],
extensions: [".css", ".js", ".jsx", ".scss", ".ts", ".tsx"],
},
plugins: [
new webpack.DefinePlugin({
"process.env": JSON.stringify(process.env),
}),
new InterpolateHtmlPlugin({
PUBLIC_URL: process.env.PUBLIC_URL,
}),
],
};
};
module.exports = (env) => {
return merge(commonConfig(env), devConfig(env));
};