This repository has been archived by the owner on Jan 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathwebpack.config.js
76 lines (74 loc) · 2.12 KB
/
webpack.config.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var webpack = require("webpack");
var HtmlWebpackPlugin = require("html-webpack-plugin");
var { CleanWebpackPlugin } = require("clean-webpack-plugin");
var path = require("path");
require("dotenv").config();
module.exports = (env) => {
let mode = "";
let devtool = "";
if (env && env.prod) {
// prod config
mode = "production";
devtool = "cheap-module-source-map";
} else {
// dev config
mode = "development";
devtool = "inline-source-map";
}
return {
entry: {
app: "./src/client/index.tsx"
},
resolve: {
extensions: [".tsx", ".ts", ".js"]
},
mode,
devtool,
devServer: {
open: true,
port: process.env.CLIENT_PORT
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: "ts-loader",
exclude: /node_modules/
},
{
test: /\.css$/,
use: [
{
loader: "style-loader"
},
{
loader: "css-loader",
options: {
sourceMap: true
}
}
]
}
]
},
output: {
path: path.join(__dirname, "./dist/client"),
filename: "[name].[fullhash].js",
chunkFilename: "[name].bundle.js"
},
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuild: ["./dist"]
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, "./src/client/index.html")
}),
new webpack.DefinePlugin({
"process.env": {
CLIENT_PORT: JSON.stringify(process.env.CLIENT_PORT),
SERVER_PORT: JSON.stringify(process.env.SERVER_PORT)
}
})
]
};
};