forked from getfider/fider
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
executable file
·117 lines (111 loc) · 2.99 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
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const publicFolder = path.resolve(__dirname, "public");
const isProduction = process.env.NODE_ENV === "production";
const plugins = [
new MiniCssExtractPlugin({
filename: "css/[name].[contenthash].css",
chunkFilename: "css/[name].[contenthash].css"
}),
new ForkTsCheckerWebpackPlugin({ checkSyntacticErrors: true }),
new BundleAnalyzerPlugin({
analyzerMode: "disabled", // To visualize the treemap of dependencies, change "disabled" to "static" and remove statsOptions
generateStatsFile: true,
statsFilename: "assets.json",
statsOptions: {
assets: false,
children: false,
chunks: false,
entrypoints: true,
chunkGroups: true,
modules: false
}
})
];
if (!isProduction) {
const CleanObsoleteChunks = require("webpack-clean-obsolete-chunks");
plugins.push(new CleanObsoleteChunks());
}
// On Development Mode, we allow Assets to be up to 14 times bigger than on Production Mode
const maxSizeFactor = isProduction ? 1 : 14;
module.exports = {
mode: process.env.NODE_ENV || "development",
entry: {
main: "./public/index.tsx",
vendor: [
"react",
"react-dom",
"tslib",
"marked",
"react-textarea-autosize",
"react-icons/lib"
],
},
output: {
path: __dirname + "/dist",
filename: "js/[name].[contenthash].js",
publicPath: "/assets/",
},
devtool: "source-map",
resolve: {
extensions: [".mjs", ".ts", ".tsx", ".js"],
alias: {
"@fider": publicFolder
}
},
performance: {
maxEntrypointSize: 327680 * maxSizeFactor, // 320 KiB. Should ideally be ~240 KiB
maxAssetSize: 194560 * maxSizeFactor, // 190 KiB
hints: "error"
},
module: {
rules: [
{
test: /\.(css|scss)$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"sass-loader"
]
},
{
test: /\.(ts|tsx)$/,
include: publicFolder,
loader: "ts-loader",
options: {
transpileOnly: true
}
},
{
test: /\.(svg?)(\?[a-z0-9=&.]+)?$/,
include: publicFolder,
loader: "file-loader?name=images/[name].[hash].[ext]"
}
]
},
optimization: {
splitChunks: {
cacheGroups: {
common: {
chunks: 'all',
name: 'common',
test: /[\\/]public[\\/](components|services|models)[\\/]/
},
vendor: {
chunks: 'all',
name: 'vendor',
test: 'vendor'
},
}
}
},
plugins,
stats: {
assets: true,
children: false,
entrypoints: false,
modules: false,
}
};