forked from ss220club/Paradise-SS220
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
150 lines (142 loc) · 3.71 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
/**
* @file
* @copyright 2020 Aleksej Komarov
* @license MIT
*/
const webpack = require('webpack');
const path = require('path');
const ExtractCssPlugin = require('mini-css-extract-plugin');
const { createBabelConfig } = require('./babel.config.js');
const createStats = (verbose) => ({
assets: verbose,
builtAt: verbose,
cached: false,
children: false,
chunks: false,
colors: true,
entrypoints: true,
hash: false,
modules: false,
performance: false,
timings: verbose,
version: verbose,
});
module.exports = (env = {}, argv) => {
const mode = argv.mode === 'production' ? 'production' : 'development';
const config = {
mode,
context: path.resolve(__dirname),
target: ['web', 'es5', 'browserslist:ie 11'],
entry: {
'tgui': ['./packages/tgui-polyfill', './packages/tgui'],
'tgui-panel': ['./packages/tgui-polyfill', './packages/tgui-panel'],
'tgui-say': ['./packages/tgui-polyfill', './packages/tgui-say'],
},
output: {
path: argv.useTmpFolder ? path.resolve(__dirname, './public/.tmp') : path.resolve(__dirname, './public'),
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js',
chunkLoadTimeout: 15000,
hashFunction: 'xxhash64',
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: {},
},
module: {
rules: [
{
test: /\.(js|cjs|ts|tsx)$/,
use: [
{
loader: require.resolve('babel-loader'),
options: createBabelConfig({ mode }),
},
],
},
{
test: /\.scss$/,
use: [
{
loader: ExtractCssPlugin.loader,
options: {
esModule: false,
},
},
{
loader: require.resolve('css-loader'),
options: {
esModule: false,
},
},
{
loader: require.resolve('sass-loader'),
},
],
},
{
test: /\.(png|jpg|svg)$/,
type: 'asset/inline',
},
],
},
optimization: {
emitOnErrors: false,
realContentHash: true,
moduleIds: 'deterministic',
},
performance: {
hints: false,
},
devtool: false,
cache: {
type: 'filesystem',
cacheLocation: path.resolve(__dirname, `.yarn/webpack/${mode}`),
buildDependencies: {
config: [__filename],
},
},
stats: createStats(true),
plugins: [
new webpack.EnvironmentPlugin({
NODE_ENV: env.NODE_ENV || argv.mode || 'development',
WEBPACK_HMR_ENABLED: env.WEBPACK_HMR_ENABLED || argv.hot || false,
DEV_SERVER_IP: env.DEV_SERVER_IP || null,
}),
new ExtractCssPlugin({
filename: '[name].bundle.css',
chunkFilename: '[name].bundle.css',
}),
],
};
// Add a bundle analyzer to the plugins array
if (argv.analyze) {
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
config.plugins = [...config.plugins, new BundleAnalyzerPlugin()];
}
// Production build specific options
if (argv.mode === 'production') {
const { EsbuildPlugin } = require('esbuild-loader');
config.optimization.minimizer = [
new EsbuildPlugin({
target: 'ie11',
css: true,
}),
];
}
// Development build specific options
if (argv.mode !== 'production') {
config.devtool = 'cheap-module-source-map';
}
// Development server specific options
if (argv.devServer) {
config.devServer = {
progress: false,
quiet: false,
noInfo: false,
clientLogLevel: 'silent',
stats: createStats(false),
};
}
return config;
};