-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
153 lines (143 loc) · 4.19 KB
/
Copy pathwebpack.config.js
File metadata and controls
153 lines (143 loc) · 4.19 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const path = require("path");
const Terser = require("terser-webpack-plugin");
const HTMLWebpackPlugin = require("html-webpack-plugin");
const HtmlInlineScriptPlugin = require("html-inline-script-webpack-plugin");
const WatchExternalFilesPlugin = require('webpack-watch-files-plugin').default;
const { defaultMinimizerOptions } = require("html-loader");
const { version } = require("./package.json");
const { DefinePlugin } = require("webpack");
const MODE = process.env.MODE.replace(/\-tamper/, "");
const isProd = MODE === "production";
for (const key in defaultMinimizerOptions) {
defaultMinimizerOptions[key] = isProd;
}
class BannerPlugin {
constructor(banner) {
this.banner = banner;
}
apply(compiler) {
compiler.hooks.emit.tapAsync("FileListPlugin", (compilation, callback) => {
for (const chunk of compilation.chunks) {
for (const filename of chunk.files) {
const asset = compilation.assets[filename];
const code = asset._value.match(/^\(\(\)(\s*=>\s*\{.+)\(\);?$/ms)[1];
asset._value = this.banner.replace(/\{CODE\}/, "((GM_info)" + code);
}
}
callback();
})
}
}
const plugins = [
new WatchExternalFilesPlugin({
files: [
"./src/**/**/*",
"./src/**/*",
"./src/*",
"./public/**/**/*",
"./public/**/*",
"./public/*",
]
}),
new DefinePlugin({
PRODUCTION: isProd
})
];
if (isProd) {
plugins.push(
new BannerPlugin(`// ==UserScript==
// @name Dsync Client [Sploop.io]
// @author Murka
// @description The most advanced hack for sploop.io
// @icon https://sploop.io/img/ui/favicon.png
// @version ${version}
// @match *://sploop.io/*
// @run-at document-start
// @grant none
// @license MIT
// @namespace https://greasyfork.org/users/919633
// ==/UserScript==
/* jshint esversion:6 */
/*
Author: Murka
Github: https://github.com/Murka007/Dsync-client
Discord: https://discord.gg/sG9cyfGPj5
Greasyfork: https://greasyfork.org/en/scripts/449995-dsync-client-sploop-io
I need your support, please follow these steps:
1. Join my DISCORD server
2. Write a feedback about this script on GREASYFORK "script works, thank you so much"
3. Star my repository on GITHUB
*/\n\nFunction("(" + {CODE}.toString() + \`)(\${JSON.stringify(GM_info)});\`)();`)
)
}
if (!process.env.MODE.endsWith("-tamper")) {
plugins.push(
new HTMLWebpackPlugin({
title: "Dsync client",
inject: "body",
minify: {
collapseWhitespace: isProd,
minifyCSS: isProd,
minifyJS: isProd
}
}),
new HtmlInlineScriptPlugin()
)
}
module.exports = {
mode: MODE,
target: ["web", "es2020"],
entry: "./src/index.ts",
output: {
filename: "Dsync_Client.user.js",
path: path.resolve(__dirname, isProd ? "build" : "dist"),
clean: true
},
optimization: {
minimizer: [
new Terser({
terserOptions: {
compress: false,
mangle: false,
parse: false,
output: false,
format: {
beautify: true,
}
}
})
]
},
plugins: plugins,
resolve: {
extensions: [".ts", ".js", ".scss"]
},
module: {
rules: [
{
test: /\.ts$/,
use: "ts-loader",
exclude: /node-modules/
},
{
test: /\.scss$/i,
use: [
"raw-loader",
"sass-loader",
],
},
{
test: /\.html$/,
use: {
loader: "html-loader",
options: {
minimize: {
...defaultMinimizerOptions,
removeComments: true
}
}
}
}
]
}
}