-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
89 lines (82 loc) · 2.97 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
77
78
79
80
81
82
83
84
85
86
87
88
89
const path = require("path")
// const CopyPlugin = require("copy-webpack-plugin")
const pathTo = dir => (...file) => path.join(__dirname, dir, ...file)
const src = pathTo("src")
// const dist = (...file) => path.join(__dirname, "dist", ...file)
/**
* @type {import("webpack").ConfigurationFactory}
* @param {"development" | "test" | "production" | undefined} env
* @param {import("webpack").CliConfigOptions & {
* debug?: boolean;
* port?: number;
* output?: string | ((...files: string[]) => string);
* }} argv
*/
module.exports = (env,
{ // Command line args
debug,
mode,
port = 9000,
output = "dist"
}
) => (
// Do some basic logging and stuff
debug && console.log("[BUILD] Debug flag set"),
env == null && console.log("[BUILD] env not set, using default value.", env),
// Set default values
env = env ?? (debug ? "development" : "production"),
mode = mode ?? (env === "test" ? "production" : env),
output = pathTo(output),
// More logging after defaults are set
console.log("[BUILD] Building application in", mode, "mode and in environment", env),
// Build the webpack config object
{
entry: "./src/index.ts",
output: {
path: output(),
filename: "index.js",
},
mode,
devtool: (env === "production" ? "eval" : "source-map"),
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: "ts-loader",
options: {
compilerOptions: {
// sourceMap: env === "production",
// inlineSourceMap: env !== "production"
},
reportFiles: [
"src/**/*.{ts,tsx}",
"!*.spec.{ts,tsx}",
"!*.test.{ts,tsx}",
]
}
}
],
exclude: [
/node_modules/
],
} // !ts-loader
], // !rules
}, // !module
resolve: {
extensions: [".tsx", ".ts", ".js", ".jsx"],
},
// plugins: [
// new CopyPlugin({
// patterns: [{ from: "./*", to: "..", context: "public" }]
// })
// ],
devServer: {
contentBase: output(),
port,
compress: true,
hot: true,
allowedHosts: [".umd.edu"],
}
});