forked from openscopeproject/TrguiNG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
176 lines (170 loc) · 5.86 KB
/
webpack.common.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
* TrguiNG - next gen remote GUI for transmission torrent daemon
* Copyright (C) 2023 qu1ck (mail at qu1ck.org)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { execaSync } from "execa";
import path from "path";
import { readFile, writeFile, mkdir } from "fs/promises";
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import CopyPlugin from "copy-webpack-plugin";
import * as url from "url";
export const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
const tsConfig = JSON.parse(await readFile("./tsconfig.json"));
const tauriConf = JSON.parse(await readFile("./src-tauri/tauri.conf.json"));
const gitVersion = execaSync("git", ["describe", "--tags", "--dirty", "--always"]);
const versionInfo = `{
"gitVersion": "${gitVersion.stdout}",
"backendVersion": "${tauriConf.package.version}",
"buildDate": ${Date.now()}
}`;
console.log(versionInfo);
await mkdir(path.join(__dirname, "src/build/"), { recursive: true });
await writeFile(path.resolve(path.join(__dirname, "src/build/version.json")), versionInfo);
export default (mode) => ({
mode,
entry: {
main: "./src/index.tsx",
createtorrent: "./src/createtorrent.tsx",
},
plugins: [
new HtmlWebpackPlugin({
title: "Transmission GUI",
template: "src/index.html",
excludeChunks: ["createtorrent"],
templateParameters: {
reactDevTools: mode === "production" ? "" : "<script src=\"http://localhost:8097\"></script>",
},
}),
new HtmlWebpackPlugin({
title: "Create torrent",
template: "src/index.html",
filename: "createtorrent.html",
chunks: ["createtorrent"],
templateParameters: {
reactDevTools: mode === "production" ? "" : "<script src=\"http://localhost:8097\"></script>",
},
}),
new MiniCssExtractPlugin({
filename: "[name].bundle.css",
}),
new CopyPlugin({
patterns: [
{ from: "./src-tauri/icons/32x32.png", to: "favicon.png" },
{ from: "./src-tauri/icons/128x128.png", to: "favicon128.png" },
],
}),
],
output: {
filename: "[name].[contenthash].bundle.js",
path: path.resolve(__dirname, "dist"),
clean: true,
},
experiments: {
topLevelAwait: true,
},
module: {
rules: [
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.svg$/,
issuer: /\.css$/,
type: "asset/inline",
},
{
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
use: ["@svgr/webpack"],
},
],
parser: {
javascript: {
exportsPresence: "error",
importExportsPresence: "error",
},
},
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
modules: [
path.resolve(__dirname, "node_modules"),
path.resolve(__dirname, tsConfig.compilerOptions.baseUrl),
],
},
// cache: false,
stats: {
preset: "normal",
modulesSpace: 35,
modulesSort: "!size",
groupModulesByPath: false,
groupModulesByExtension: false,
// moduleAssets: false,
// orphanModules: true,
},
optimization: {
splitChunks: {
// include all types of chunks
chunks: "all",
cacheGroups: {
react: {
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
name: "vendors/react",
},
mantine: {
test: /[\\/]node_modules[\\/]@mantine[\\/]/,
name: "vendors/mantine",
},
tanstack: {
test: /[\\/]node_modules[\\/]@tanstack[\\/]/,
name: "vendors/tanstack",
},
reactdnd: {
test: /[\\/]node_modules[\\/]react-beautiful-dnd[\\/]/,
name: "vendors/reactdnd",
},
tauri: {
test: /[\\/]node_modules[\\/]@tauri-apps[\\/]/,
name: "vendors/tauri-api",
},
icons: {
test: /[\\/]node_modules[\\/]react-bootstrap-icons[\\/]/,
name: "vendors/bootstrap-icons",
},
flags: {
test: /[\\/]node_modules[\\/]flag-icons[\\/]/,
name: "vendors/flag-icons",
reuseExistingChunk: false,
enforce: true,
},
// other: {
// test: /[\\/]node_modules[\\/]/,
// priority: -1,
// name: "vendors/other",
// },
},
},
runtimeChunk: "single",
moduleIds: "deterministic",
},
});