-
Notifications
You must be signed in to change notification settings - Fork 19
/
webpack.config.js
100 lines (98 loc) · 2.46 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const path = require("path");
const webpack = require("webpack");
const WebpackObfuscator = require("webpack-obfuscator");
const obfuscatorOptions = require("./obfuscator");
module.exports = ({
filename,
filetype,
funcname,
compress,
antibot,
delay,
}) => {
const commonConfig = {
mode: "production",
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
entry: "./src/index.js",
module: {
rules: [
// NOTE: Defines string names,
// used because webpack.DefinePlugin globals obfuscation issues.
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: "string-replace-loader",
options: {
multiple: [
{ search: "dont_change_filename_var", replace: filename },
{ search: "dont_change_content_type_var", replace: filetype },
{ search: "dontChangeFunctionName", replace: funcname },
],
},
},
},
// NOTE: embed out payload to js
{
test: /assets\/.*/,
exclude: /node_modules/,
use: {
loader: "binary-loader",
},
},
// NOTE: support for older browsers
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
},
// NOTE: heavy obfuscation
{
test: /.*/,
enforce: "post",
// NOTE: excluded core-js because it takes too long to obfuscate
exclude: /node_modules\/core-js/,
use: {
loader: WebpackObfuscator.loader,
options: obfuscatorOptions,
},
},
],
},
plugins: [
// NOTE: Defines boolean globals to change execution flow.
new webpack.DefinePlugin({
CONFIG_COMPRESS: JSON.stringify(compress),
CONFIG_ANTIBOT: JSON.stringify(antibot),
CONFIG_DELAY: JSON.stringify(delay),
}),
],
};
return [
{
output: {
path: path.resolve(__dirname, "dist"),
filename: "payload.umd.js",
libraryTarget: "umd",
},
...commonConfig,
},
{
output: {
path: path.resolve(__dirname, "dist"),
filename: "payload.esm.js",
libraryTarget: "module",
},
experiments: {
outputModule: true,
},
...commonConfig,
},
];
};