-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
179 lines (159 loc) · 5.22 KB
/
webpack.config.js
File metadata and controls
179 lines (159 loc) · 5.22 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import path from "path";
import webpack from "webpack";
import CopyPlugin from "copy-webpack-plugin";
import { fileURLToPath } from "url";
import fs from "fs";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
let entry = ["./src/client/index.tsx"];
let plugins = [];
let debug = true;
let devtool = debug ? "eval-source-map" : "source-map";
let profiler = debug;
entry.unshift("core-js/stable");
export default (env, argv) => {
const prod = argv?.mode === "production";
const haxe = env?.haxe === true || env?.haxe === "true";
const haxePlatform = env?.haxePlatform;
const mode = prod ? "production" : "development";
const archMacroMap = {
"x86_64": "HXCPP_M64",
"x86": "HXCPP_M32",
"arm64": "HXCPP_ARM64",
"armv7": "HXCPP_ARMV7",
};
const arch = env?.arch || "x86_64";
const hxcppArchDefine = archMacroMap[arch];
plugins.push(
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(mode),
PROFILER: JSON.stringify(profiler),
DEBUG: JSON.stringify(!prod),
PLATFORM: JSON.stringify("web"),
})
);
const outputPath = path.resolve(__dirname, "dist");
if (prod) {
plugins.push(
new CopyPlugin({
patterns: [
{
from: "src/client/resources",
to: haxe ? "assets" : "",
globOptions: { ignore: ["**/.DS_Store"] },
},
],
})
);
if (haxe) {
plugins.push(
new CopyPlugin({
patterns: [
{
from: "src/haxe",
to: "",
globOptions: { ignore: ["**/.DS_Store"] },
},
{
from: "icons",
to: "icons",
globOptions: { ignore: ["**/.DS_Store"] },
},
],
})
);
const hxmlPath = path.resolve(outputPath, "compile.hxml");
const hxmlLines = [];
hxmlLines.push("--cpp out");
hxmlLines.push("--main Main");
hxmlLines.push("--dce full");
hxmlLines.push("--macro macros.AssetsMacro.build()");
const desktopPlatforms = ["windows", "linux", "mac", "macos"];
const mobilePlatforms = ["android", "ios", "iphone", "iphoneos"];
if (desktopPlatforms.includes(haxePlatform)) {
hxmlLines.push("--library hxwebview");
hxmlLines.push("-D desktop");
hxmlLines.push("-D no-console");
} else if (mobilePlatforms.includes(haxePlatform)) {
hxmlLines.push("--library extension-webview");
hxmlLines.push("-D mobile");
}
if (haxePlatform === "windows") {
hxmlLines.push("-D windows");
hxmlLines.push("-D resourceFile=..\\icon.rc");
}
if (haxePlatform === "linux") hxmlLines.push("-D linux");
if (haxePlatform === "mac" || haxePlatform === "macos") {
hxmlLines.push("-D mac");
hxmlLines.push("-D macos");
}
if (haxePlatform === "android") hxmlLines.push("-D android");
if (haxePlatform === "ios" || haxePlatform === "iphone" || haxePlatform === "iphoneos") {
hxmlLines.push("-D ios");
hxmlLines.push("-D iphone");
hxmlLines.push("-D iphoneos");
}
if (hxcppArchDefine) hxmlLines.push(`-D ${hxcppArchDefine}`);
hxmlLines.push("-D HXCPP_CHECK_POINTER");
hxmlLines.push("-D HXCPP_STACK_LINE");
hxmlLines.push("-D HXCPP_STACK_TRACE");
hxmlLines.push("-D HXCPP_CATCH_SEGV");
fs.mkdirSync(outputPath, { recursive: true });
fs.writeFileSync(hxmlPath, hxmlLines.join("\n"));
}
debug = false;
} else {
entry.push("webpack-dev-server/client?http://localhost:4000");
plugins.push(
new CopyPlugin({
patterns: [
{
from: "src/client/resources",
to: "",
globOptions: { ignore: ["**/.DS_Store"] },
},
],
})
);
}
const config = {
entry,
output: {
path: outputPath,
filename: haxe ? "assets/static/js/index.js" : "static/js/index.js",
},
devServer: {
static: "./dist",
},
devtool,
target: "web",
mode,
module: {
noParse: /.*[/\\]bin[/\\].+\.js/,
rules: [
{ test: /\.tsx$/, use: [{ loader: "ts-loader" }], exclude: /node_modules/ },
{ test: /\.ts$/, use: [{ loader: "ts-loader" }], exclude: /node_modules/ },
{
test: /.jsx?$/,
include: [path.resolve(__dirname, "src")],
use: [{ loader: "babel-loader", options: { presets: ["@babel/preset-react", "@babel/preset-env"] } }],
},
{ test: /\.js$/, include: [path.resolve(__dirname, "src")], use: [{ loader: "babel-loader", options: { presets: ["@babel/preset-env"] } }] },
{ test: /\.(html|htm)$/, use: [{ loader: "dom" }] },
{ test: /\.mst$/, use: [{ loader: "raw-loader" }] },
],
},
optimization: { minimize: prod, usedExports: true },
plugins,
resolve: {
alias: {
platform: path.resolve(__dirname, "./src/client/platform/web"),
api: path.resolve(__dirname, "./src/api"),
client: path.resolve(__dirname, "./src/client"),
TypedObserver: path.resolve(__dirname, "./src/client/TypedObserver"),
},
extensions: [".tsx", ".ts", ".jsx", ".js"],
},
};
return config;
};