-
Notifications
You must be signed in to change notification settings - Fork 9
/
webpack.config.js
283 lines (270 loc) · 9.85 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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/**
* @author hexxone / https://hexx.one
*
* @license
* Copyright (c) 2024 hexxone All rights reserved.
* Licensed under the GNU GENERAL PUBLIC LICENSE.
* See LICENSE file in the project root for full license information.
*
* Webpack build config for AudiOrbits.
* Probably not a good example to start from :D
*/
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const path = require('path');
const { networkInterfaces } = require('os');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
// custom plugins
const OfflinePlugin = require('./src/we_utils/src/offline/OfflinePlugin');
const WascBuilderPlugin = require('./src/we_utils/src/wasc-worker/WascBuilderPlugin');
const RenamerPlugin = require('./src/we_utils/src/renamer/RenamerPlugin');
const lanIp
= networkInterfaces().Ethernet.find((item) => {
return item.family === 'IPv4' && !item.internal && item.address;
}).address ?? '0.0.0.0';
console.log(`Got Lan IP: ${lanIp}`);
module.exports = (env) => {
const prod = env.production || false;
const stringMode = prod ? 'production' : 'development';
return {
mode: stringMode,
entry: {
ao: {
import: './src/AudiOrbi.ts'
}
},
// compile target
// target: ["web", "es6", "es2020"],
output: {
chunkFormat: 'module',
path: path.resolve(__dirname, 'dist', stringMode),
// publicPath: "dist/" + stringMode,
library: {
name: 'ao',
type: 'var' // window
},
// libraryTarget: "commonjs",
// filename: "ao.js",
filename: '[name].js',
chunkFilename: '[name].js',
globalObject: 'this'
},
// remove dead code
optimization: {
minimize: true,
nodeEnv: stringMode,
minimizer: [
new TerserPlugin({
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
terserOptions: {
// ecma: 2020,
// parse: {},
// compress: {
// unsafe: prod,
// hoist_funs: prod,
// },
format: {
comments: false
},
mangle: {
properties: {
keep_quoted: true,
// reserved: propss,
regex: /_(private|internal)_/ // the same prefixes like for custom transformer
}
},
module: true,
toplevel: true,
sourceMap: false,
// keep_fnames: !prod,
keep_classnames: !prod
},
extractComments: false
})
],
chunkIds: 'size',
concatenateModules: true,
moduleIds: 'size',
mangleExports: 'size',
mangleWasmImports: true,
providedExports: true,
usedExports: true,
innerGraph: true
},
devtool: false,
module: {
rules: [
// loader for workers...
// {
// test: /\.worker\.js$/i,
// loader: "src/we_utils/src/worker-loader-fork/src/index.js",
// options: {
// esModule: true,
// filename: "asdasd.foo.js",
// chunkFilename: "sdf.custom.js",
// },
// },
// loader for Typescript
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
options: {
compiler: 'typescript', // ttypescript
transpileOnly: true
// getCustomTransformers: (program) => {
// return {
// before: prod
// ? [
// propertiesRenameTransformer(program, {
// entrySourceFiles: ["main.ts"],
// reserved: ["a", "b", "c", "d", "w", "x", "y", "z", "min", "max"],
// // noImplicitAny: true,
// }),
// ]
// : [],
// };
// },
}
},
// Process any JS outside of the app with Babel.
{
test: /\.jsx?$/, // If you are using TypeScript: /\.tsx?$/
include: path.resolve(__dirname, 'src'),
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true
}
}
]
},
// shader loader
{
test: /\.(glsl)$/,
loader: require.resolve(
'./src/we_utils/src/three/shader/loader'
)
},
// exclude .asc from the bundle
{
test: /.*\.asc$/i,
loader: 'null-loader'
}
]
},
resolveLoader: {
alias: {
'worker-loader': path.resolve(
__dirname,
'./src/we_utils/src/worker-loader-fork/dist'
)
}
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.glsl'],
// plugins: [new TsconfigPathsPlugin({ configFile: "./tsconfig.json" })],
alias: {
'we_utils/src': path.resolve(__dirname, './src/we_utils/src'),
'three.ts/src': path.resolve(
__dirname,
'./src/we_utils/src/three.ts/src'
)
// reverse mapping shaders (dont get copied by tsc)
// "fragment/*.glsl": path.resolve(__dirname, "./src/we_utils/src/three/shader/fragment"),
}
},
// plugins
plugins: [
// copy static files
new CopyWebpackPlugin({
patterns: [
{
from: 'public'
}
]
}),
// manual wasm module build
// just so you don't have to modify the process everytime...
// this will compile all modules in 'rootpath' (recursive)
// where the 'include' (regex) matches a filename.
new WascBuilderPlugin({
production: prod,
basedir: '../../../../assembly',
modules: ['BasicGeometry.ts', 'FractalGeometry.ts'],
cleanup: true,
shared: true
}),
new WascBuilderPlugin({
production: prod,
basedir: '../weas/assembly',
modules: ['WEAS.ts'],
cleanup: true,
shared: true
}),
// offline worker helper
// will create a list of all app-files.
// this list is used to cache the app offline in browser.
new OfflinePlugin({
staticdir: `${__dirname}\\public`,
outfile: 'offlinefiles.json',
extrafiles: ['/'],
pretty: !prod
}),
// webpack bundle analyzer
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: '../out/ao_bundle_report.html',
openAnalyzer: false
}),
// custom renamer
new RenamerPlugin({
regex: /[a-z0-9_]*_webpack_[a-z0-9_]*/gi
}),
// detect circular
new CircularDependencyPlugin({
exclude: /node_modules/,
include: /dist/,
failOnError: true
})
],
devServer: {
host: lanIp,
allowedHosts: ['all'], // or use 'auto' for slight more security
static: {
directory: path.resolve(__dirname, 'dist', stringMode),
watch: true
},
client: false,
liveReload: false,
compress: true,
https: {
key: fs.readFileSync('../../localhost+1-key.pem'),
cert: fs.readFileSync('../../localhost+1.pem')
// ca: fs.readFileSync("ca.crt"),
},
server: 'https',
// disableHostCheck: true,
hot: false,
port: 8443,
headers: {
https: true,
'Access-Control-Allow-Origin': '*',
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp'
}
},
// print statistics
stats: {
children: true,
errorDetails: true,
// Display bailout reasons
optimizationBailout: true
}
};
};