-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
executable file
·159 lines (156 loc) · 5.29 KB
/
webpack.config.ts
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
import path from "path";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import {Configuration as DevConfiguration} from "webpack-dev-server";
import {Configuration, ProgressPlugin, EnvironmentPlugin} from "webpack";
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
import merge from "webpack-merge";
import FaviconsWebpackPlugin from "favicons-webpack-plugin";
import ESLintWebpackPlugin from "eslint-webpack-plugin";
import corejsJson from "core-js/package.json";
import ourJson from "./package.json";
import {BundleAnalyzerPlugin} from "webpack-bundle-analyzer";
interface KnownEnv {
WEBPACK_SERVE: boolean
}
const options: (env: KnownEnv) => Configuration = (env) => {
const format = env.WEBPACK_SERVE ? '[name]' : '[name]-[contenthash]';
const common: Configuration = {
entry: './src/main.ts',
output: {
filename: `${format}.js`,
path: path.resolve(__dirname, 'dist'),
assetModuleFilename: `${format}[ext][query]`,
clean: true,
},
plugins: [
new EnvironmentPlugin({
'APP_VERSION': ourJson.version,
}),
new HtmlWebpackPlugin({
title: "Spider Eyes | Team 5818",
}),
new FaviconsWebpackPlugin({
logo: "./src/img/logo.png",
mode: "webapp",
favicons: {
pixel_art: true,
icons: {
favicons: true,
android: false,
appleIcon: false,
appleStartup: false,
yandex: false,
windows: false,
},
},
}),
new MiniCssExtractPlugin({
filename: `${format}.css`,
}),
new ForkTsCheckerWebpackPlugin({
typescript: {
diagnosticOptions: {
semantic: true,
},
},
}),
new ESLintWebpackPlugin({
extensions: ['ts', 'tsx'],
exclude: ['node_modules'],
}),
new ProgressPlugin(),
],
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
module: {
rules: [
{
test: /\.s[ca]ss$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
},
{
test: /\.tsx?$/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
bugfixes: true,
debug: true,
useBuiltIns: 'usage',
corejs: corejsJson.version,
shippedProposals: true,
},
],
],
},
},
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
exclude: /node_modules/,
},
],
},
optimization: {
runtimeChunk: "single",
splitChunks: {
chunks: "all",
cacheGroups: {
react: {
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
name: 'react',
chunks: 'all',
},
reactstrap: {
test: /[\\/]node_modules[\\/](reactstrap.*)[\\/]/,
name: 'reactstrap',
chunks: 'all',
},
},
},
},
performance: {
maxEntrypointSize: 512000,
},
};
if (env.WEBPACK_SERVE) {
return merge(common, {
mode: 'development',
devtool: 'source-map',
devServer: {
static: './dist',
port: 9323,
},
});
} else {
return merge(common, {
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: "static",
openAnalyzer: false,
}),
],
devtool: 'source-map',
mode: 'production',
optimization: {
removeAvailableModules: true,
},
});
}
};
export default options;