-
Notifications
You must be signed in to change notification settings - Fork 216
/
webpack.config.js
132 lines (127 loc) · 3.49 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
const webpack = require('webpack')
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const HappyPack = require("happypack");
const WebpackBuildNotifierPlugin = require("webpack-build-notifier");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const path = require("path");
const { merge } = require("webpack-merge");
module.exports = (_notSureWhatThatArgumentDoes, env) => {
// note: webpack-command used to pass `env` as the
// first argument, but webpack-command died. I advise
// not switching to webpack-nano, as it's from the same
// maintainer and might also die. wepback-cli seems to
// pass env as the second argument.
return [
merge(getCommonConfig("main", env), {
target: "electron-main",
resolve: {
alias: { "react-dom": "@hot-loader/react-dom" },
mainFields: ["electron-main", "module", "main"],
},
entry: {
main: ["./src/main/index.ts"],
"inject-game": ["./src/main/inject/inject-game.ts"],
"inject-captcha": ["./src/main/inject/inject-captcha.ts"],
"inject-preload": ["./src/main/inject/inject-preload.ts"],
},
plugins: [
new CleanWebpackPlugin(),
new WebpackBuildNotifierPlugin({
title: "itch (main)",
}),
],
}),
merge(getCommonConfig("renderer", env), {
target: "web",
resolve: {
mainFields: ["browser", "module", "main"],
},
entry: {
renderer: ["./src/renderer/index.tsx"],
},
externals: ["systeminformation"],
module: {
rules: [
{
test: /\.(png|svg|woff|woff2)$/,
use: [{ loader: "file-loader" }],
},
{
test: /\.css$/,
use: [{ loader: "style-loader" }, { loader: "css-loader" }],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new WebpackBuildNotifierPlugin({
title: "itch (renderer)",
}),
new HtmlWebpackPlugin({
filename: "index.html",
template: path.resolve(`./src/index.ejs`),
minify: false,
}),
new webpack.ProvidePlugin({
process: "process/browser",
Buffer: ['buffer', 'Buffer'],
}),
],
devServer: {
hot: true,
host: "localhost",
contentBase: __dirname,
},
}),
];
};
function getCommonConfig(type, env) {
const isProduction = env.mode === "production";
const mode = isProduction ? "production" : "development";
return {
mode,
devtool: isProduction ? "source-map" : "eval",
node: {
__dirname: true,
__filename: true,
},
output: {
filename: "[name].bundle.js",
chunkFilename: "[name].chunk.js",
libraryTarget: "var",
library: "LIB",
path: path.resolve(`./dist/${type}`),
},
resolve: {
extensions: [".ts", ".tsx", ".js"],
plugins: [new TsconfigPathsPlugin({})],
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: "/node_modules/",
use: [{ loader: "happypack/loader?id=ts" }],
},
],
},
plugins: [
new HappyPack({
id: "ts",
threads: 4,
loaders: [
{
path: "ts-loader",
query: { happyPackMode: true },
},
],
verbose: false,
}),
],
optimization: {
minimize: false,
minimizer: [],
},
};
}