-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
68 lines (63 loc) · 1.86 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
import childProcess from "child_process";
import DotenvWebpackPlugin from "dotenv-webpack";
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default (env) => {
let appVersion;
if (env?.APP_VERSION) {
appVersion = env.APP_VERSION;
} else {
const gitCommit = childProcess.execSync("git rev-parse HEAD").toString();
const commitDate = new Date(
Number(childProcess.execSync("git show -s --format=%ct HEAD").toString().trim()) * 1000,
);
appVersion = `dev-${gitCommit.slice(0, 7)} - ${commitDate.toISOString()}`;
}
return {
entry: "./client/index.ts",
module: {
rules: [
{
test: /\.ts$/,
use: "ts-loader",
include: [path.resolve(__dirname, "client"), path.resolve(__dirname, "common")],
},
{
test: /\.s?css$/,
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
include: path.resolve(__dirname, "client/styles"),
},
{
test: /\.(jpg|png)$/,
include: path.resolve(__dirname, "client/assets"),
type: "asset/resource",
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
output: {
filename: "bundle.js",
assetModuleFilename: "assets/[hash].[name][ext][query]",
path: path.resolve(__dirname, "build"),
clean: true,
},
plugins: [
new HtmlWebpackPlugin({
template: "./client/index.html",
appVersion,
}),
new MiniCssExtractPlugin(),
new DotenvWebpackPlugin({
safe: ".env.defaults",
defaults: ".env.defaults",
systemvars: true,
}),
],
};
};