-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
webpack.config.ts
149 lines (148 loc) · 5.08 KB
/
webpack.config.ts
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
import wasmPackPlugin from "@wasm-tool/wasm-pack-plugin";
import compressionWebpackPlugin from "compression-webpack-plugin";
import copyWebpackPlugin from "copy-webpack-plugin";
import eslintPlugin from "eslint-webpack-plugin";
import htmlWebpackPlugin from "html-webpack-plugin";
import path from "path";
import type ts from "typescript";
import glslMinifyTransformer from "typescript-glslminify-transformer";
import type webpack from "webpack";
import type { Configuration as WebpackDevServerConfiguration } from "webpack-dev-server";
export default (env: any): webpack.Configuration & { devServer?: WebpackDevServerConfiguration } => ({
entry: "./src/Test/index.ts",
output: {
path: path.join(__dirname, "/test_dist"),
filename: "[name].bundle.js",
clean: true
},
optimization: {
minimize: env.production,
splitChunks: {
chunks: "all",
cacheGroups: {
glslShaders: {
test: (module: { type: string; resource: string | undefined }): boolean => {
if (module.resource === undefined) {
return false;
}
const resource = module.resource.replace(/\\/g, "/");
if (resource.includes("Shaders/")) {
return true;
}
return false;
},
name: "glslShaders",
chunks: "async",
enforce: true
},
wgslShaders: {
test: (module: { type: string; resource: string | undefined }): boolean => {
if (module.resource === undefined) {
return false;
}
const resource = module.resource.replace(/\\/g, "/");
if (resource.includes("ShadersWGSL/")) {
return true;
}
return false;
},
name: "wgslShaders",
chunks: "async",
enforce: true
}
}
}
},
cache: true,
module: {
rules: [
{
test: /\.tsx?$/,
loader: "ts-loader",
options: {
getCustomTransformers: (program: ts.Program) => ({
before: [glslMinifyTransformer(program, { customPrefixes: ["glsl", "wgsl"] })]
})
}
},
{
test: /\.m?js$/,
resolve: {
fullySpecified: false
}
},
{
test: /\.html$/,
loader: "html-loader"
}
]
},
resolve: {
alias: {
// eslint-disable-next-line @typescript-eslint/naming-convention
"@": path.resolve(__dirname, "src")
},
modules: ["src", "node_modules"],
extensions: [".js", ".jsx", ".ts", ".tsx"],
fallback: {
"fs": false,
"path": false
}
},
node: {
global: false,
// eslint-disable-next-line @typescript-eslint/naming-convention
__filename: false,
// eslint-disable-next-line @typescript-eslint/naming-convention
__dirname: false
},
plugins: ([
new htmlWebpackPlugin({
template: "./src/Test/index.html"
}),
new eslintPlugin({
extensions: ["ts", "tsx"],
fix: true,
cache: true,
configType: "flat"
}),
new copyWebpackPlugin({
patterns: [
{ from: "res", to: "res" }
]
})
] as webpack.Configuration["plugins"])!.concat(env.wasmInstance !== "js" ? [
new wasmPackPlugin({
crateDirectory: path.resolve(__dirname, "src/Runtime/Optimized/wasm_src"),
outDir: path.resolve(__dirname, "src/Runtime/Optimized/wasm/" + env.wasmInstance),
outName: "index",
extraArgs: "--target web",
forceMode: "development"
})
] : []).concat(env.production ? [
new compressionWebpackPlugin({
test: /\.(js|wasm|bvmd|bpmx)$/i
}) as any
] : []),
devServer: {
host: "0.0.0.0",
port: 20310,
allowedHosts: "all",
client: {
logging: "none"
},
hot: true,
watchFiles: ["src/**/*"],
server: "https",
headers: {
// eslint-disable-next-line @typescript-eslint/naming-convention
"Cross-Origin-Opener-Policy": "same-origin",
// eslint-disable-next-line @typescript-eslint/naming-convention
"Cross-Origin-Embedder-Policy": "require-corp"
}
},
ignoreWarnings: [
(warning): boolean => warning.message.includes("Circular dependency between chunks with runtime")
],
mode: env.production ? "production" : "development"
});