-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
112 lines (109 loc) · 2.97 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
const path = require("path");
const HWP = require("html-webpack-plugin");
const webpack = require("webpack");
const commitHash = require("child_process").execSync(
"git rev-parse --short HEAD",
);
const CompressionPlugin = require("compression-webpack-plugin");
const ImageMinimizerPlugin = require("image-minimizer-webpack-plugin");
const getCurrentTimeEST = () => {
const now = new Date();
const options = {
timeZone: "America/New_York",
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hour12: false,
};
return new Intl.DateTimeFormat("en-US", options).format(now).replace(",", "");
};
const currentTime = getCurrentTimeEST();
const FaviconsWebpackPlugin = require("favicons-webpack-plugin");
module.exports = {
entry: path.join(__dirname, "/src/index.js"),
output: {
filename: "build.js",
path: path.join(__dirname, "/dist"),
publicPath: "/",
assetModuleFilename: (pathData) => {
const filepath = path
.dirname(pathData.filename)
.split("/")
.slice(1)
.join("/");
return `${filepath}/[name].[hash][ext][query]`;
},
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
},
{
test: /\.md$/,
loader: "raw-loader",
},
{
test: /\.css$/i,
include: path.resolve(__dirname, "src"),
use: ["style-loader", "css-loader", "postcss-loader"],
},
{
test: /\.(png|jpeg|jpg|gif|svg|eot|ttf|woff|woff2)$/,
type: "asset",
},
],
},
// TODO: why is this not working :(
// optimization: {
// minimizer: [
// new ImageMinimizerPlugin({
// minimizer: {
// implementation: ImageMinimizerPlugin.sharpMinify,
// options: {
// failOnError: false,
// encodeOptions: {
// jpeg: {
// quality: 90,
// },
// // png by default sets the quality to 100%, which is same as lossless
// // https://sharp.pixelplumbing.com/api-output#png
// png: {},
// // gif does not support lossless compression at all
// // https://sharp.pixelplumbing.com/api-output#gif
// gif: {},
// },
// },
// },
// }),
// ],
// },
devServer: {
historyApiFallback: true,
},
plugins: [
new HWP({ template: path.join(__dirname, "/src/index.html") }),
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
new FaviconsWebpackPlugin({
logo: "./src/assets/mil_white.svg",
}),
new webpack.DefinePlugin({
COMMIT_HASH: JSON.stringify(commitHash.toString().trim()),
BUILD_TIME: JSON.stringify(currentTime),
}),
new CompressionPlugin(),
],
resolve: {
extensions: [".ts", ".js"],
fallback: {
buffer: require.resolve("buffer"),
},
},
};