-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
80 lines (70 loc) · 2.02 KB
/
webpack.config.js
File metadata and controls
80 lines (70 loc) · 2.02 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
import { execSync } from "child_process";
import webpack from "webpack";
import { resolve } from "path";
import { dirname } from "path";
import { fileURLToPath } from "url";
import semver from "semver";
function debugInfo() {
const GIT_TAG = execSync("git describe --tags --abbrev=0").toString().trim();
const GIT_TAG_COMMIT = execSync(`git rev-parse --short ${GIT_TAG}`).toString().trim();
const GIT_COMMIT = execSync("git rev-parse --short HEAD").toString().trim();
const IS_CLEAN = execSync("git status --porcelain").toString().trim() === "";
let current_version = semver.parse(GIT_TAG);
if (GIT_TAG_COMMIT !== GIT_COMMIT) {
current_version = current_version.inc("patch");
}
let version_string = current_version.toString();
if (!IS_CLEAN) {
version_string += "+build";
}
return {
APP_VERSION: "v" + version_string,
GIT_COMMIT,
};
}
const info = debugInfo();
const __dirname = dirname(fileURLToPath(import.meta.url));
/** @returns {webpack.Configuration} */
const config = (env) => {
return {
output: {
path: resolve(__dirname, "dist", env.DIST),
filename: "[name].js",
publicPath: "http://localhost:8080/",
},
module: {
rules: [
{
test: /\.(j|t)sx?$/,
use: "swc-loader",
exclude: /node_modules/,
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: "asset/inline",
},
{
test: /\.html$/i,
loader: "html-loader",
},
{
test: /iframe\.ts$/,
loader: "val-loader",
},
],
},
plugins: [
new webpack.ProgressPlugin({}),
new webpack.DefinePlugin({
"process.env.APP_VERSION": JSON.stringify(info.APP_VERSION),
"process.env.GIT_COMMIT": JSON.stringify(info.GIT_COMMIT),
"process.env.BROWSER": JSON.stringify(env.BROWSER),
}),
],
resolve: {
tsconfig: resolve(__dirname, "tsconfig.json"),
extensions: [".tsx", ".ts", ".js"],
},
};
};
export default config;