-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
99 lines (98 loc) · 3.38 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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const path = require('path');
const TerserPlugin = require("terser-webpack-plugin");
const webpack = require('webpack');
const package = require('./package.json');
const { execSync } = require('child_process')
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = (_, mode) => {
const isProduction = (typeof mode.env.production === "boolean" && mode.env.production);
return {
entry: {
index: "./src/index.ts"
},
mode: isProduction ? "production" : "development",
devtool: isProduction ? undefined : 'inline-source-map',
output: {
publicPath: '',
filename: '[name].js',
chunkFilename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
},
resolve: {
extensions: [ ".js", ".ts" ]
},
stats: 'minimal',
experiments: {
topLevelAwait: true
},
module: {
rules: [
{
test: /\.(png|jpe?g|gif|svg)$/i,
use: 'file-loader'
},
{
test: /\.ts$/,
loader: "ts-loader"
},
{
test: /\.css$/i,
use: [
{
loader: MiniCssExtractPlugin.loader
},
'css-loader'
]
}
]
},
devServer: {
port: 80,
host: '0.0.0.0',
hot: false
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css'
}),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
inject: 'body',
chunks: [ 'index' ],
template: './src/index.html',
filename: 'index.html',
favicon: './res/favicon.ico',
minify: isProduction ? { minifyCSS: true, minifyJS: true, removeComments: true } : undefined
}),
new webpack.DefinePlugin({
VERSION: JSON.stringify(package.version.toString()),
COMPILED_AD: JSON.stringify(new Date()),
CONFIG: JSON.stringify(require("./config.json")),
NEWS: JSON.stringify(require("./news.json")),
LAST_COMMIT: JSON.stringify(execSync("git rev-parse HEAD").toString().trim())
}),
new CopyWebpackPlugin({
patterns: [
{ from: 'static/images', to: 'images' },
{ from: 'static/manifest', to: 'manifest' },
]
})
],
optimization: isProduction ? {
minimize: true,
emitOnErrors: false,
usedExports: true,
minimizer: [ new TerserPlugin(), new CssMinimizerPlugin() ],
splitChunks: {
chunks: 'async',
maxAsyncRequests: 30,
maxInitialRequests: 30
}
} : undefined
}
}