-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
103 lines (94 loc) · 2.98 KB
/
webpack.config.ts
File metadata and controls
103 lines (94 loc) · 2.98 KB
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
import childProcess from "child_process";
import path from "path";
import CopyWebpackPlugin from "copy-webpack-plugin";
import HtmlWebpackPlugin from "html-webpack-plugin";
import { TsconfigPathsPlugin } from "tsconfig-paths-webpack-plugin";
import { Configuration, DefinePlugin } from "webpack";
import { merge } from "webpack-merge";
import { bugs, description, homepage, keywords, productName, repository, synopsis, version } from "./package.json";
interface Environment {
mode?: "development" | "production";
}
const BUILD_CONSTANTS = {
BUILD_DATE: Date.now(),
BUILD_TIMEZONE: Intl.DateTimeFormat().resolvedOptions().timeZone,
ISSUES_URL: bugs.url,
REPOSITORY_URL: repository.url,
REVISION: childProcess.execSync("git describe --tags --always --first-parent --dirty").toString().trim(),
VERSION: version
};
const commonConfig: Configuration = {
entry: {
app: path.resolve(__dirname, "src/app/index.tsx")
},
output: {
filename: "[name].[contenthash].js",
path: path.resolve(__dirname, "build/dist"),
publicPath: "/",
assetModuleFilename: "assets/[name].[contenthash][ext]"
},
optimization: {
splitChunks: {
chunks: "all",
name: "vendors"
}
},
performance: {
hints: false
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
plugins: [new TsconfigPathsPlugin()]
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: "babel-loader",
exclude: /node_modules/
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
},
{
test: /\.(jpg|woff|woff2)$/,
type: "asset/resource"
}
]
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(__dirname, "public")
}
]
}),
new DefinePlugin(Object.fromEntries(Object.entries(BUILD_CONSTANTS).map(([key, value]) => [`__${key}__`, JSON.stringify(value)]))),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "src/resources/templates/index.ejs"),
templateParameters: {
description,
homepage,
keywords,
productName,
title: `${productName} • ${synopsis}`
}
})
]
};
const developmentConfig: Configuration = {
mode: "development",
devtool: "source-map"
};
const productionConfig: Configuration = {
mode: "production",
devtool: "cheap-module-source-map"
};
const config = (env: Environment): Configuration => {
const mode = env.mode || "production";
console.log(`Building ${productName} in ${mode} mode...`);
return mode === "production" ? merge(commonConfig, productionConfig) : merge(commonConfig, developmentConfig);
};
export default config;