-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
131 lines (126 loc) · 3.59 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
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require("path")
const glob = require("glob")
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin")
const PurgecssPlugin = require("purgecss-webpack-plugin")
const SpriteLoaderPlugin = require("svg-sprite-loader/plugin")
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin
const publicFolder = path.resolve(__dirname, "public")
const localeFolder = path.resolve(__dirname, "locale")
const isProduction = process.env.NODE_ENV === "production"
const plugins = [
new MiniCssExtractPlugin({
filename: "css/[name].[contenthash].css",
chunkFilename: "css/[name].[contenthash].css",
}),
new ForkTsCheckerWebpackPlugin(),
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,
},
}),
new PurgecssPlugin({
paths: glob.sync(`./public/**/*.{html,tsx}`, { nodir: true }),
defaultExtractor: (content) => content.match(/[^<>"'`\s]*[^<>"'`\s:]/g) || [],
safelist: [/--/, /__/, /data-/],
}),
new SpriteLoaderPlugin({ plainSprite: true }),
]
// 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",
},
output: {
path: __dirname + "/dist",
filename: "js/[name].[contenthash].js",
publicPath: "/assets/",
clean: true,
},
devtool: "source-map",
resolve: {
extensions: [".mjs", ".ts", ".tsx", ".js", ".svg"],
alias: {
"@fider": publicFolder,
"@locale": localeFolder,
},
},
performance: {
maxEntrypointSize: 368640 * maxSizeFactor, // 360 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, localeFolder],
loader: "babel-loader",
},
{
test: /\.(json)$/,
include: localeFolder,
loader: "@lingui/loader",
type: "javascript/auto",
},
{
test: /\.svg$/,
include: publicFolder,
loader: "svg-sprite-loader",
options: {
esModule: false,
extract: true,
outputPath: "icons/",
spriteFilename: "sprite.[hash].svg",
publicPath: "/assets/icons/",
},
},
],
},
optimization: {
moduleIds: "deterministic",
runtimeChunk: "single",
splitChunks: {
cacheGroups: {
common: {
chunks: "all",
name: "common",
test: /[\\/]public[\\/](components|services|models)[\\/]/,
},
markdown: {
chunks: "all",
name: "markdown",
test: /dompurify|marked/,
},
vendor: {
chunks: "all",
name: "vendor",
test: /(react($|\/)|react-dom|tslib|react-textarea-autosize|@lingui\/core)/,
},
},
},
},
plugins,
stats: {
assets: true,
children: false,
entrypoints: false,
modules: false,
},
}