-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.mjs
120 lines (116 loc) · 2.81 KB
/
webpack.config.mjs
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
import * as path from 'path';
import webpack from 'webpack';
import Dotenv from 'dotenv-webpack';
import TerserPlugin from 'terser-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import HtmlInlineScriptPlugin from 'html-inline-script-webpack-plugin';
import ngrok from 'ngrok';
import qrcode from 'qrcode-terminal';
const PRODUCTION = 'production';
const mode = process.env.NODE_ENV || PRODUCTION;
const isProd = mode === PRODUCTION;
export const debug = process.env.DEBUG || !isProd;
const OUTPUT_DIR = path.resolve('./public');
export default {
mode,
entry: {
game: {
import: './src/index.ts'
}
},
output: {
filename: '[name].js',
path: OUTPUT_DIR,
iife: false,
},
module: {
rules: [
{
test: /\.m?js$/,
enforce: 'pre',
use: 'source-map-loader',
},
{
test: /\.(m?js|ts)$/,
use: 'babel-loader',
},
],
},
resolve: {
extensions: ['.js', '.mjs', '.ts'],
},
optimization: {
minimize: isProd,
minimizer: [
new TerserPlugin({
terserOptions: {
ecma: 2015,
module: true,
toplevel: true,
compress: {
passes: 5,
drop_console: true,
unsafe: true,
unsafe_arrows: true,
unsafe_math: true,
unsafe_methods: true,
},
mangle: {
module: true,
properties: {
keep_quoted: true,
// socket.io functions
reserved: ['connected', 'emit', 'off', 'once'],
}
}
},
}),
],
},
devtool: isProd ? false : 'source-map',
devServer: {
allowedHosts: [
'localhost',
'.ngrok.io'
],
onListening({ options: { port } }) {
ngrok.connect({ port })
.then((url) => {
console.log(`ngrok is running at ${url}`);
qrcode.generate(url, {small: true});
});
},
},
plugins: [
new webpack.DefinePlugin({
'process.env.DEBUG': !isProd,
MUGL_DEBUG: !isProd,
NGL_ENABLE_BLEND: true,
NGL_ENABLE_STENCIL: false,
NGL_ENABLE_RASTER: false,
NGL_ENABLE_OFFSCREEN: false,
NGL_ENABLE_MRT: false,
NGL_ENABLE_SCISSOR: false,
NGL_ENABLE_TEXTURE: false,
}),
new Dotenv(),
new HtmlWebpackPlugin({
template: './assets/index.html',
inject: 'body',
scriptLoading: 'blocking',
minify: isProd ? {
collapseWhitespace: true,
keepClosingSlash: true,
minifyCSS: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true
} : false,
}),
...(isProd ? [
new HtmlInlineScriptPlugin()
] : []),
],
};