-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathwebpack.config.js
More file actions
128 lines (125 loc) · 4.84 KB
/
Copy pathwebpack.config.js
File metadata and controls
128 lines (125 loc) · 4.84 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
const path = require("path");
const fs = require("fs");
const { DefinePlugin } = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
// App directory
const appDirectory = fs.realpathSync(process.cwd());
/**
* Single webpack configuration for every mode this template supports:
*
* webpack serve -> dev server, hot reload, opens a browser
* webpack serve --env test -> dev server for Playwright (no hot reload, no browser)
* webpack --env production -> minified production bundle
* webpack -> unminified development bundle
*/
module.exports = (env = {}) => {
const isProduction = !!env.production;
const isTest = !!env.test;
const showSceneControls = !isTest && (!isProduction || !!env.demo);
return {
mode: isProduction ? "production" : "development",
devtool: isProduction ? "source-map" : "inline-source-map",
entry: path.resolve(appDirectory, "src/index.ts"),
output: {
filename: "js/[name].js",
path: path.resolve("./dist/"),
chunkFilename: "js/[name].[contenthash].js",
clean: true,
},
resolve: {
extensions: [".ts", ".js"],
fallback: {
fs: false,
path: false, // require.resolve("path-browserify")
},
},
module: {
rules: [
{
test: /\.(js|mjs|jsx|ts|tsx)$/,
loader: "source-map-loader",
enforce: "pre",
},
{
test: /\.tsx?$/,
loader: "ts-loader",
// sideEffects: true
},
{
test: /\.(glsl|vs|fs)$/,
loader: "ts-shader-loader",
exclude: /node_modules/,
},
{
test: /\.(png|jpg|gif|env|glb|gltf|stl)$/i,
type: "asset",
parser: {
dataUrlCondition: {
maxSize: 8192,
},
},
},
],
},
plugins: [
new DefinePlugin({
__DEV_CONTROLS__: JSON.stringify(showSceneControls),
}),
new HtmlWebpackPlugin({
inject: true,
template: path.resolve(appDirectory, "public/index.html"),
}),
],
optimization: {
splitChunks: {
// `chunks: "initial"` keeps code that only a lazily-loaded scene needs out of
// the initial payload. Modules shared between scenes are still deduplicated
// into a shared async chunk by webpack's default cache group.
cacheGroups: {
webgpuShaders: {
name: "webgpu-shaders",
chunks: "initial",
priority: 50,
enforce: true,
test: (module) => /\/ShadersWGSL\//.test(module.resource),
},
webglShaders: {
name: "webgl-shaders",
chunks: "initial",
priority: 50,
enforce: true,
test: (module) => /\/Shaders\//.test(module.resource),
},
webgpuExtensions: {
name: "webgpu-extensions",
chunks: "initial",
priority: 50,
enforce: true,
test: (module) => /\/WebGPU\//.test(module.resource),
},
babylonBundle: {
name: "babylonBundle",
chunks: "initial",
priority: 30,
reuseExistingChunk: true,
test: (module) => /\/node_modules\/@babylonjs\//.test(module.resource),
},
},
},
usedExports: true,
// Minifying development builds only makes them slow to produce and hard to debug.
minimize: isProduction,
},
devServer: {
static: path.resolve(appDirectory, "public"),
compress: true,
// The Playwright tests want a plain static server: no hot reload, no live-reload
// websocket and no browser window, so runs stay deterministic.
hot: !isTest,
open: !isTest,
webSocketServer: isTest ? false : undefined,
// host: '0.0.0.0', // enable to access from other devices on the network
// https: true // enable when HTTPS is needed (like in WebXR)
},
};
};