-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.common.js
108 lines (104 loc) · 2.78 KB
/
webpack.common.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
const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const CompressionPlugin = require("compression-webpack-plugin");
const threadLoader = require("thread-loader");
const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
const smp = new SpeedMeasurePlugin();
// custom config
const { webpackPaths } = require("./settings");
threadLoader.warmup([
"babel-loader",
"file-loader",
"cache-loader",
"css-loader",
"babel-loader",
]);
module.exports = smp.wrap({
entry: {
app: "./src/index.js",
Home: path.resolve(__dirname, "src/home.js"),
Heroes: path.resolve(__dirname, "src/Components/Hero/Heroes.js"),
Artifacts: path.resolve(__dirname, "src/Components/Artifacts/Artifacts.js"),
},
output: {
path: path.resolve(__dirname, "build"),
filename: "[name].[hash].js",
publicPath: "/",
chunkFilename: "[name].[hash].js",
},
module: {
rules: [
{
// workaround
// https://github.com/graphql/graphql-js/issues/2721#issuecomment-723008284
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
},
{
test: /\.js$/,
include: path.resolve("src"),
use: ["thread-loader", "babel-loader"],
},
{
test: /\.(jpe?g|gif|png|svg|woff|ttf|wav|mp3|bmp|avif)$/,
type: "asset/resource",
},
{
test: /\.css$/i,
use: [
{ loader: MiniCssExtractPlugin.loader, options: { publicPath: "/" } },
"css-loader",
],
},
{
test: /\.ext$/,
use: ["cache-loader", "css-loader", "file-loader"],
include: path.resolve("src"),
},
],
},
resolve: {
alias: {
...webpackPaths(),
},
},
optimization: {
runtimeChunk: "single",
splitChunks: {
chunks: "all",
maxInitialRequests: 20,
maxSize: 244000,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
const packageName = module.context.match(
/[\\/]node_modules[\\/](.*?)([\\/]|$)/
)[1];
return `npm.${packageName.replace("@", "")}`;
},
},
},
},
minimizer: [new CssMinimizerPlugin({ exclude: /(node_modules)/ })],
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: "./public/index.html",
}),
new MiniCssExtractPlugin(),
new CompressionPlugin({
filename: "[path].gz",
algorithm: "gzip",
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8,
}),
],
});