-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
154 lines (143 loc) · 4.93 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
function htmlWebpackPluginCommon(configArgs, mergeIn) {
// Merge mergeIn with some common options
return Object.assign(
{
filename: "index.html",
template: path.resolve(__dirname, "src", "index.html"),
chunks: [],
//chunks: ["index"],
minify: (configArgs.mode === "production"),
title: "Sim's Monster Hunter Fansite",
author: "simshadows",
description: "Sim's Monster Hunter Fansite",
keywords: "Monster Hunter Rise, Builder, Damage, Calculator, EFR",
canonical: "https://monsterhunter.simshadows.com",
favicon: path.resolve(__dirname, "src", "mhrb", "_images", "derived", "armour_head_r1.png"),
},
mergeIn,
);
}
const config = (configArgs) => ({
mode: configArgs.mode,
entry: {
//"index": path.resolve(__dirname, "src", "_app", "index.ts"),
"mhrb/index": path.resolve(__dirname, "src", "mhrb", "_app", "index.ts"),
},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "dist"),
assetModuleFilename: "images/[name]-[hash][ext]",
clean: true,
},
resolve: {
// This is done as a hack to get the Typescript tooling to work since you're not allowed
// to include the ".ts" extension when importing modules within a Typescript file.
// I would prefer if I just included file extensions explicitly.
extensions: [".ts", ".js"],
},
plugins: [
new HtmlWebpackPlugin(htmlWebpackPluginCommon(configArgs, {})),
new HtmlWebpackPlugin(htmlWebpackPluginCommon(configArgs, {
filename: "mhrb/index.html",
template: path.resolve(__dirname, "src", "mhrb", "index.html"),
chunks: ["mhrb/index"],
title: "MHR Builder",
author: "simshadows",
description: "A web-based build calculator for Monster Hunter Rise.",
canonical: "https://monsterhunter.simshadows.com/mhrb",
})),
new MiniCssExtractPlugin({
filename: "[name].css",
}),
new ForkTsCheckerWebpackPlugin({
typescript: {
diagnosticOptions: { // To be honest, I have no idea what this is doing yet
semantic: true,
syntactic: true,
declaration: true,
global: true,
},
mode: "write-references",
},
}),
new CopyPlugin({
patterns: [
{ from: "public" },
],
}),
],
module: {
rules: [
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: "asset/inline", // Use this if you want inlined image files (best performance!)
//type: "asset/resource", // Use this if you want separate image files (could be useful for debugging!)
},
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
{
test: /\.js$/i,
use: {
loader: "babel-loader",
options: {
presets: [
["@babel/preset-env"],
["@babel/preset-react"],
],
},
},
},
{
test: /\.ts$/i,
use: {
loader: "babel-loader",
options: {
presets: [
["@babel/preset-env"],
["@babel/preset-react"],
["@babel/preset-typescript"],
],
},
},
},
],
},
optimization: {
minimize: (configArgs.mode === "production"),
minimizer: [
new TerserPlugin(),
new CssMinimizerPlugin(),
],
},
devServer: {
static: {
directory: path.join(__dirname, "dist"),
},
compress: true,
port: 8000,
},
});
module.exports = (env, argv) => {
console.log("env:");
console.log(env);
console.log();
console.log("argv:");
console.log(argv);
console.log();
const configArgs = {
mode: "production",
};
if (["production", "development", "none"].includes(argv.mode)) {
configArgs.mode = argv.mode;
}
return config(configArgs);
};