-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
89 lines (78 loc) · 2.37 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
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
// const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const isEnvProduction = process.env.NODE_ENV === "production";
module.exports = {
entry: "./src/index.jsx",
mode: isEnvProduction ? "production" : "development",
devtool: isEnvProduction ? false : "cheap-module-source-map",
output: {
path: path.resolve(__dirname, "dist"),
filename: "static/js/[name].[contenthash:12].js",
chunkFilename: "static/js/[name].[contenthash:12].chunk.js",
},
plugins: [
new CopyPlugin({
patterns: [{ from: "src/assets/robots.txt" }],
}),
new HtmlWebpackPlugin({
title: "Ted Pennings",
template: "src/assets/index.html",
hash: true,
}),
// new BundleAnalyzerPlugin(),
],
resolve: {
extensions: [".js", ".jsx", ".mjs", ".mdx", ".json"],
alias: {
"react-dom$": "react-dom/profiling",
"scheduler/tracing": "scheduler/tracing-profiling",
},
},
optimization: {
minimize: isEnvProduction,
minimizer: [new TerserPlugin()],
},
devServer: {
compress: true,
port: 3000,
historyApiFallback: true,
},
module: {
rules: [
// "oneOf" will traverse all following loaders until one will
// match the requirements. When no loader matches it will fall
// back to the "file" loader at the end of the loader list.
{
oneOf: [
{
test: /\.(jpe?g|png|webp)$/i,
loader: require.resolve("responsive-loader"),
options: {
adapter: require("responsive-loader/sharp"),
name: "static/media/[name].[contenthash:12].[ext]",
sizes: [1024, 99999],
},
},
{
test: /\.(m?jsx?)$/,
loader: require.resolve("babel-loader"),
resolve: {
fullySpecified: false,
},
},
{ test: /.mdx$/, use: ["babel-loader", "@mdx-js/loader"] },
{
loader: require.resolve("file-loader"),
exclude: [/\.(jsx?)$/, /\.html$/, /\.json$/],
options: {
name: "static/media/[name].[contenthash:12].[ext]",
},
},
],
},
],
},
};