forked from JustOptimize/ShowHiddenChannels
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
72 lines (63 loc) · 2.31 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
const path = require('path');
const webpack = require('webpack');
const pluginConfig = require('./src/config.json');
const process = require('process');
const meta = (() => {
const lines = ['/**'];
for (const key in pluginConfig) {
lines.push(` * @${key} ${pluginConfig[key]}`);
}
lines.push(' */');
return lines.join('\n');
})();
module.exports = {
mode: 'development',
target: 'node',
devtool: false,
entry: './src/index.js',
output: {
filename: 'ShowHiddenChannels.plugin.js',
// todo: use github releases instead -> path.join(__dirname, 'dist')
// eslint-disable-next-line no-undef
path: __dirname,
libraryTarget: 'commonjs2',
libraryExport: 'default',
compareBeforeEmit: false,
},
resolve: {
extensions: ['.js', '.css', '.jsx'],
},
module: {
rules: [
{ test: /\.css$/, use: 'raw-loader' },
{ test: /\.jsx$/, exclude: /node_modules/, use: 'babel-loader' },
],
},
plugins: [
new webpack.BannerPlugin({ raw: true, banner: meta }),
{
apply: (compiler) => {
compiler.hooks.assetEmitted.tap('ShowHiddenChannels', (filename, info) => {
console.info(`\n\nℹ️ Plugin built as ${filename}\n`);
const userConfig = (() => {
if (process.platform === 'win32') return process.env.APPDATA;
if (process.platform === 'darwin') {
return path.join(process.env.HOME, 'Library', 'Application Support');
}
if (process.env.XDG_CONFIG_HOME) {
return process.env.XDG_CONFIG_HOME;
}
return path.join(process.env.HOME, 'Library', '.config');
})();
const fs = require('fs');
const bdFolder = path.join(userConfig, 'BetterDiscord');
fs.copyFileSync(info.targetPath, path.join(bdFolder, 'plugins', filename));
console.info(`\n\n✅ Copied to BD folder\n`);
});
},
},
new webpack.DefinePlugin({
__VERSION__: JSON.stringify(pluginConfig.version),
}),
],
};