This repository has been archived by the owner on May 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathwebpack.config.js
75 lines (71 loc) · 2.52 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
75
const webpack = require('webpack')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const path = require('path')
const about = require('./package.json')
module.exports = (_, argv) => {
// Output directly into BetterDiscord plugins
// process.env.APPDATA: 'C:\\Users\\user\\AppData\\Roaming', Windows only
// process.env.HOME: '/home/user' on Linux, '/Users/user' on MacOS, Linux and MacOS only
let appdata = process.env.APPDATA || path.resolve(process.env.HOME, (process.platform === 'darwin' ? 'Library/Preferences' : '.config'))
let config = {
entry: { app: './index-betterdiscord.js' },
output: {
path: path.resolve(appdata, 'BetterDiscord/plugins'),
filename: `${about.id}.plugin.js`,
library: '_' + about.id, // Expose the bundle as variable
libraryTarget: 'var'
},
resolve: {
extensions: ['.js', '.css', '.sass', '.scss', '.pug'],
alias: { '#': __dirname }
},
plugins: [
// Add BetterDiscord plugin metadata at the top of the bundle
// ID with an underscore on purpose, upon class instantiation, will assign instantiated class to non-underscored variable
new webpack.BannerPlugin({ banner: `//META{"name":"_${about.id}"}*//`, raw: true, entryOnly: true })
],
module: {
rules: [
{ test: /\.scss$/, use: ['to-string-loader', 'css-loader', 'sass-loader'] },
{ test: /\.pug$/, use: ['pug-loader'] }
]
}
}
if (argv.mode !== 'development') {
// Production mode as is seems to put it's plugins after the banner,
// one of those plugins is JS uglifier, so the banner is getting stripped out of output
config = {
...config,
performance: { hints: 'warning' },
output: {
...config.output,
pathinfo: false
},
optimization: {
namedModules: false,
namedChunks: false,
nodeEnv: 'production',
flagIncludedChunks: true,
occurrenceOrder: true,
sideEffects: true,
usedExports: true,
concatenateModules: true,
splitChunks: {
hidePathInfo: true,
minSize: 30000,
maxAsyncRequests: 5,
maxInitialRequests: 3
},
noEmitOnErrors: true,
checkWasmTypes: true
},
plugins: [
new UglifyJsPlugin(),
new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify('production') }),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.NoEmitOnErrorsPlugin()
].concat(config.plugins)
}
}
return config
}