-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
executable file
·82 lines (77 loc) · 2.39 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
import ReactRouterToArray from "react-router-to-array";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import OptimizeCSSAssetsPlugin from "optimize-css-assets-webpack-plugin";
import StaticSiteGeneratorPlugin from "static-site-generator-webpack-plugin";
import UglifyJsPlugin from "uglifyjs-webpack-plugin";
import webpack from "webpack";
module.exports = () => {
// Prevent webpack from attempting to process css before loaders are configured
require.extensions[".css"] = () => {};
// Workaround for legacy SSL removal in Node 17+
const crypto = require("crypto");
const cryptoOrigCreateHash = crypto.createHash;
crypto.createHash = algorithm =>
cryptoOrigCreateHash(algorithm === "md4" ? "sha256" : algorithm);
// Routes array is required in config.plugins
const routes = ReactRouterToArray(require("./src/scripts/routes"));
const config = {
devServer: { historyApiFallback: true, inline: false, stats: "minimal" },
entry: "./src/scripts/entry.js",
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
query: { presets: ["env", "react"] },
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: "css-loader", options: { importLoaders: 1 } },
"postcss-loader",
],
},
{
test: /\.woff$/,
loader: "url-loader?mimetype=application/font-woff",
},
{
test: /\.(jpg)$/,
loader: "file-loader",
options: { name: "assets/[name].[ext]" },
},
{
test: /\_redirects$/,
loader: "file-loader",
options: { name: "[name]" },
},
{
test: /\.(ico|png|svg|webmanifest|xml)$/,
loader: "file-loader",
options: { name: "[name].[ext]" },
},
],
},
optimization: {
minimizer: [
new UglifyJsPlugin({ cache: true, parallel: true }),
new OptimizeCSSAssetsPlugin(),
],
},
output: {
filename: "bundle.js",
globalObject: "this",
libraryTarget: "umd",
path: __dirname + "/build",
publicPath: "/",
},
plugins: [
new MiniCssExtractPlugin({ filename: "styles.css" }),
new StaticSiteGeneratorPlugin("bundle.js", routes),
],
stats: "minimal",
};
return config;
};