forked from JJoriping/KKuTu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
94 lines (88 loc) · 3.03 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
const File = require("fs")
const { resolve } = require("path")
const { BannerPlugin } = require("webpack")
const TerserPlugin = require("terser-webpack-plugin")
const LICENSE = [
"Rule the words! KKuTu Online",
"Copyright (C) 2017 JJoriping([email protected])",
"",
"This program is free software: you can redistribute it and/or modify",
"it under the terms of the GNU General Public License as published by",
"the Free Software Foundation, either version 3 of the License, or",
"(at your option) any later version.",
"",
"This program is distributed in the hope that it will be useful,",
"but WITHOUT ANY WARRANTY; without even the implied warranty of",
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the",
"GNU General Public License for more details.",
"",
"You should have received a copy of the GNU General Public License",
"along with this program. If not, see <http://www.gnu.org/licenses/>.",
].join("\n")
class ConcatPlugin {
constructor({ files, destination }) {
this.files = files
this.destination = destination
}
apply(compiler) {
const result = ["/**", LICENSE, "*/", "(function(){"]
compiler.hooks.beforeCompile.tap("ConcatPlugin", () => {
this.files
.filter((file) => File.existsSync(file))
.forEach((file) => result.push(File.readFileSync(file, "utf8")))
result.push("})();")
File.writeFileSync(this.destination, result.join("\n"), {
encoding: "UTF-8",
})
})
}
}
const sourcePath = resolve(__dirname, "dist/Web/lib")
const gameSourcePath = resolve(sourcePath, "kkutu")
const distributionPath = resolve(__dirname, "dist/Web/public/js")
const files = File.readdirSync(sourcePath, { withFileTypes: true })
.filter((u) => u.isFile())
.map((u) => u.name)
module.exports = {
mode: "production",
target: "web",
/*
inline-source-map은 개발 시 개발자 도구 이용을 쉽게 해 줍니다.
production mode에서는 주석 처리하는 것을 권장합니다. (파일 용량이 커짐)
*/
// devtool: "inline-source-map",
entry: files.reduce((etr, file) => {
etr[file.substring(0, file.length - 3)] = resolve(sourcePath, file)
return etr
}, {}),
output: {
path: distributionPath,
filename: "[name].min.js",
},
plugins: [
new ConcatPlugin({
files: [
resolve(gameSourcePath, "head.js"),
resolve(gameSourcePath, "ready.js"),
resolve(gameSourcePath, "rule_classic.js"),
resolve(gameSourcePath, "rule_jaqwi.js"),
resolve(gameSourcePath, "rule_crossword.js"),
resolve(gameSourcePath, "rule_typing.js"),
resolve(gameSourcePath, "rule_hunmin.js"),
resolve(gameSourcePath, "rule_daneo.js"),
resolve(gameSourcePath, "rule_sock.js"),
resolve(gameSourcePath, "body.js"),
resolve(gameSourcePath, "tail.js"),
],
destination: resolve(sourcePath, "in_game_kkutu.js"),
}),
new BannerPlugin(LICENSE),
],
optimization: {
minimizer: [
new TerserPlugin({
extractComments: false,
}),
],
},
}