-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
129 lines (127 loc) · 3.66 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
"use strict";
const { resolve } = require("path");
const CopyPlugin = require("copy-webpack-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const PostcssPresetEnv = require("autoprefixer");
const WebPack = require("webpack");
module.exports = (env, options) => {
const isDevMode = options.mode === "development";
return {
mode: isDevMode ? options.mode : "production",
entry: {
"main": ["./src/index.ts"],
"bootstrap": ["./src/bootstrap.ts"],
"bootstrap-style": ["./src/bootstrap-style.ts"],
"font-awesome": ["./src/font-awesome.ts"],
"style": ["./src/style.ts"],
"firebase": ["./src/firebase.ts"],
},
output: {
filename: "[name].[contenthash:8].js",
path: resolve(__dirname, "public/dist"),
clean: true,
},
resolve: {
extensions: [".ts", ".tsx", ".js"],
},
devtool: isDevMode ? "eval-source-map" : false,
plugins: [
new HtmlWebpackPlugin({
template: "./src/index.html",
filename: "../index.html",
favicon: "./src/favicon.ico",
}),
new WebPack.HotModuleReplacementPlugin(),
new CopyPlugin({
patterns: [
{
from: "src/favicon.ico",
to: "favicon.ico",
},
{
from: "src/sitemap.xml",
to: "../sitemap.xml",
},
],
}),
new MiniCssExtractPlugin({
filename: "[name].css",
}),
],
module: {
rules: [
{ test: /\.tsx?$/, use: ["ts-loader"] },
{
test: /\.css$/,
use: [isDevMode ? "style-loader" : MiniCssExtractPlugin.loader, "css-loader"],
},
{
test: /\.s[ac]ss$/,
use: [
{
loader: isDevMode ? "style-loader" : MiniCssExtractPlugin.loader,
},
{
loader: "css-loader",
options: {
url: {
filter: (url, cssPath) => !url.match(/\.(png|jpg|jpeg)$/),
},
},
},
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [require("autoprefixer")],
},
},
},
"sass-loader",
],
},
{
test: /\.html$/,
exclude: /index\.html$/,
type: "asset/resource",
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
},
{
test: /\.(svg|eot|woff|woff2|ttf)$/,
type: "asset/resource",
generator: {
filename: "./fonts/[name][hash][ext][query]",
},
},
],
},
optimization: {
minimizer: isDevMode ? [`...`] : [`...`, new CssMinimizerPlugin()],
runtimeChunk: "single",
moduleIds: "deterministic",
splitChunks: {
chunks: "all",
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
// @summary Create individual bundles for each vendor package.
// Extract the package name from the module path.
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
// npm package names are URL-safe, but some servers don't like @ symbols
return `npm.${packageName.replace("@", "")}`;
},
},
},
},
},
};
};