-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
74 lines (68 loc) · 2.34 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
const fs = require("fs");
const path = require("path");
const webpack = require("webpack");
const pkg = require("./package.json");
const pluginConfig = require("./src/config");
pluginConfig.version = pkg.version;
function buildMeta(config) {
if (config.info) config = config.info;
const metaString = ["/**"];
const line = (label, val) => val && metaString.push(` * @${label} ${val}`);
line("name", config.name);
line("description", config.description);
line("version", config.version);
line("author", config.author ?? config?.authors.map(a => a.name).join(", "));
line("authorId", config.authorId ?? config?.authors?.[0].id ?? config?.authors?.[0].discord_id);
line("authorLink", config.authorLink ?? config?.authors?.[0].link);
line("website", config.website ?? config.github);
line("source", config.source ?? config.github_raw ?? config.github);
line("donate", config.donate);
line("patreon", config.patreon);
line("invite", config.invite);
metaString.push(" */");
metaString.push("");
return metaString.join("\n") + "\n";
}
module.exports = {
mode: "development",
target: "node",
devtool: false,
entry: "./src/index.js",
output: {
filename: "PublicServers.plugin.js",
path: path.resolve(__dirname, "dist"),
libraryTarget: "commonjs2",
libraryExport: "default",
compareBeforeEmit: false
},
resolve: {
extensions: [".js", ".jsx"]
},
module: {
rules: [
{
test: /.jsx?$/,
exclude: /node_modules/,
use: ["babel-loader"]
},
{test: /\.css$/, type: "asset/source"}
]
},
optimization: {
minimize: false,
},
plugins: [
new webpack.BannerPlugin({raw: true, banner: buildMeta(pluginConfig)}),
{
apply: (compiler) => {
compiler.hooks.assetEmitted.tap("CopyToBD", (filename, info) => {
/* eslint-disable no-console */
if (!pkg.copyToBD) return;
const bdFolder = (process.platform == "win32" ? process.env.APPDATA : process.platform == "darwin" ? process.env.HOME + "/Library/Preferences" : process.env.XDG_CONFIG_HOME ? process.env.XDG_CONFIG_HOME : process.env.HOME + "/.config") + "/BetterDiscord/";
fs.copyFileSync(info.targetPath, path.join(bdFolder, "plugins", filename));
console.log(`\n\n✅ Copied to BD folder\n`);
});
}
},
]
};