forked from fms-cat/condition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
124 lines (120 loc) · 2.9 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
/* eslint-env node */
/* eslint-disable @typescript-eslint/no-var-requires */
const TerserPlugin = require( 'terser-webpack-plugin' );
const HtmlWebpackPlugin = require( 'html-webpack-plugin' );
const packageJson = require( './package.json' );
const path = require( 'path' );
const webpack = require( 'webpack' );
/**
* @type TerserPlugin.TerserPluginOptions[ 'terserOptions' ]
*/
const terserOptions = {
compress: {
arguments: true,
booleans_as_integers: true,
drop_console: true,
keep_fargs: false,
passes: 2,
unsafe_arrows: true,
unsafe_math: true,
},
mangle: {
properties: {
regex: /.+/,
keep_quoted: true,
reserved: [
// material tags
'forward',
'deferred',
'cubemap',
'depth',
]
},
},
format: {
ascii_only: true,
ecma: 2020,
},
module: true,
toplevel: true,
};
module.exports = ( env, argv ) => {
const VERSION = packageJson.version;
const DEV = argv.mode === 'development';
// console.info( `Webpack: Building ${ packageJson.name } v${ VERSION } under ${ argv.mode } settings...` );
return {
entry: path.resolve( __dirname, 'src/main.ts' ),
output: {
path: path.join( __dirname, 'dist' ),
filename: 'bundle.js',
},
resolve: {
extensions: [ '.js', '.ts' ],
},
module: {
rules: [
{
test: /automaton\.json$/,
use: [
{
loader: path.resolve( __dirname, './loaders/automaton-json-loader.js' ),
options: {
minimize: DEV ? false : {
precisionTime: 3,
precisionValue: 3,
}
}
},
],
type: 'javascript/auto',
},
{
test: /\.(glsl|frag|vert)$/,
type: 'asset/source',
use: [
// shader minifier is kinda jej
// want to try it works well in development phase
{
loader: path.resolve( __dirname, './loaders/shader-minifier-loader.js' ),
options: {
preserveExternals: true,
},
},
'glslify-loader',
],
},
{
test: /\.(opus|png)$/,
type: 'asset/inline',
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
'ts-loader',
],
},
],
},
optimization: {
minimize: !DEV,
minimizer: [ new TerserPlugin( { terserOptions } ) ],
moduleIds: DEV ? 'named' : undefined,
usedExports: !DEV,
},
devServer: {
inline: true,
hot: true
},
devtool: DEV ? 'inline-source-map' : 'source-map',
plugins: [
new webpack.DefinePlugin( {
'process.env': {
DEV,
VERSION: `"${ VERSION }"`
},
} ),
new HtmlWebpackPlugin(),
],
};
};