-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
100 lines (95 loc) · 2.9 KB
/
webpack.config.babel.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
// import CopyWebpackPlugin from "copy-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import OptimizeCSSAssetsPlugin from "optimize-css-assets-webpack-plugin";
import path from "path";
import reactRouterToArray from "react-router-to-array";
import emoji from "remark-emoji";
import StaticSiteGeneratorPlugin from "static-site-generator-webpack-plugin";
import UglifyJsPlugin from "uglifyjs-webpack-plugin";
module.exports = () => {
// Prevent webpack from trying to process files before loaders are configured
require.extensions[".css"] = () => {};
require.extensions[".mdx"] = () => {};
// Workaround for legacy SSL removal in Node 17+
const crypto = require("crypto");
const cryptoOrigCreateHash = crypto.createHash;
crypto.createHash = algorithm =>
cryptoOrigCreateHash(algorithm === "md4" ? "sha256" : algorithm);
const routes = reactRouterToArray(require("./src/routes").default);
const config = {
devServer: { inline: false, stats: "minimal" },
entry: "./src/index.js",
mode: "development",
module: {
rules: [
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: "css-loader", options: { importLoaders: 1 } },
"postcss-loader",
],
},
{
test: /\.htaccess$/,
loader: "file-loader",
options: { name: "[name]" },
},
{
test: /\.(ico|png|svg|webmanifest|xml)$/,
include: [path.resolve(__dirname, "src/assets")],
loader: "file-loader",
options: { name: "[name].[ext]" },
},
{
test: /\.(jpg|woff|woff2)$/,
loader: "file-loader",
options: { name: "assets/[name].[ext]" },
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
},
{
test: /.mdx?$/,
use: [
"babel-loader",
{
loader: "@mdx-js/loader",
options: { remarkPlugins: [emoji] },
},
],
},
{
test: /\.png$/,
include: [
path.resolve(__dirname, "src/@monospaced/modern/assets/images"),
],
loader: "file-loader",
options: { name: "assets/[name].[ext]" },
},
],
},
optimization: {
minimizer: [
new OptimizeCSSAssetsPlugin(),
new UglifyJsPlugin({ cache: true, parallel: true }),
],
},
output: {
filename: "bundle.js",
globalObject: "this",
libraryTarget: "umd",
path: `${__dirname}/build`,
publicPath: "/",
},
plugins: [
// new CopyWebpackPlugin([{ context: "src/legacy", from: "**/*" }]),
new MiniCssExtractPlugin({ filename: "styles.css" }),
new StaticSiteGeneratorPlugin("bundle.js", routes),
],
stats: "minimal",
};
return config;
};