-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
79 lines (78 loc) · 2.24 KB
/
webpack.config.js
File metadata and controls
79 lines (78 loc) · 2.24 KB
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
const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require("node:path");
const TerserPlugin = require("terser-webpack-plugin");
const buildFolder = "build";
module.exports = (_env, argv) => {
const mode = argv.mode ?? "development";
const isProductionMode = mode === "production";
return {
mode: mode,
devtool: "source-map",
entry: {
options: "./src/options.ts",
background: "./src/background.ts",
},
output: {
path: path.resolve(__dirname, buildFolder),
filename: "[name].js",
clean: isProductionMode,
},
module: {
rules: [
{
test: /\.ts$/,
use: "ts-loader",
exclude: [/node_modules/, path.resolve(__dirname, "__tests__")],
},
],
},
resolve: {
extensions: [".ts", ".js"],
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(__dirname, "icons"),
to: path.resolve(__dirname, `${buildFolder}/icons`),
globOptions: {
ignore: ["**/original.png"],
},
},
{
from: path.resolve(__dirname, "public"),
to: path.resolve(__dirname, `${buildFolder}/public`),
},
{
from: path.resolve(__dirname, "manifest.json"),
to: path.resolve(__dirname, buildFolder),
transform(input) {
const content = input.toString();
// adjust relative paths in packaged manifest.json
let newContent = content.replace(new RegExp(`(./)?${buildFolder}/`, "g"), "");
if (isProductionMode) {
// remove "dev" suffixes in manifest.json for production build
newContent = newContent
.replaceAll(" (dev)", "")
.replace("llm-thunderbird-dev@tngtech.com", "llm-thunderbird@tngtech.com");
}
return newContent;
},
},
],
}),
],
optimization: {
minimize: isProductionMode,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: ["log", "info"],
},
},
}),
],
},
};
};