-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
74 lines (72 loc) · 1.61 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
import fs from "node:fs";
import { resolve } from "node:path";
import webpack from "webpack";
import TerserPlugin from "terser-webpack-plugin";
const { BannerPlugin, ProvidePlugin } = webpack;
const __dirname = import.meta.dirname;
const banner = fs.readFileSync(
resolve(__dirname, "byw-mangadl.meta.js"),
"utf-8",
{ encoding: "utf-8", flag: "r" },
);
const headers = banner
.split("\n")
.slice(1, -1)
.map((cur) => cur.slice(3).split(" ")[0].trim());
export default function (_, argv) {
return {
entry: "./src/index.js",
mode: argv.mode || "production",
output: {
path: resolve(__dirname),
filename: "byw-mangadl.user.js",
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
use: [
{
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
},
},
],
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
{
test: /\.html$/,
use: "html-loader",
},
],
},
plugins: [
new BannerPlugin({
banner,
raw: true,
}),
new ProvidePlugin({
$: "jquery",
jQuery: "jquery",
}),
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: new RegExp(`==\/?UserScript==|${headers.join("|")}`),
},
},
extractComments: false,
}),
],
},
};
}