-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
117 lines (109 loc) · 2.84 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
113
114
115
116
117
/* eslint-env node */
import browserslist from "browserslist";
import HtmlWebpackPlugin from "html-webpack-plugin";
import fs from "node:fs";
import path from "node:path";
import url from "node:url";
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
const webRoot = path.join(__dirname, "/www/");
const frontendRoot = path.join(webRoot, "/built");
// TODO: flattern this a bit
const webBuildRoot = "/built/frontend";
const builtRoot = path.join(frontendRoot, "frontend");
fs.rmSync(builtRoot, { force: true, recursive: true });
fs.mkdirSync(builtRoot, { recursive: true });
fs.copyFileSync(
path.join(__dirname, "src/build.htaccess"),
path.join(frontendRoot, ".htaccess")
);
const browsers = browserslist();
fs.writeFileSync(
path.join(frontendRoot, "browsers.json"),
JSON.stringify({ browsers: browsers })
);
fs.writeFileSync(
path.join(frontendRoot, "release_version.txt"),
JSON.stringify(
{
date: new Date().toISOString()
// Does not work on CI
// git: child_process
// .execSync("git rev-parse HEAD", { encoding: "UTF8" })
// .trim()
},
null,
2
)
);
const isDebug = process.env.CRYPTOMEDIC_DEV ?? false;
if (isDebug) {
console.info("Webpack mode: development");
} else {
console.info("Webpack mode: production");
}
export default {
// https://webpack.js.org/guides/development/
mode: isDebug ? "development" : "production",
entry: {
ng1x: path.join(__dirname, "/legacy/app-old/main.js"),
static: path.join(__dirname, "/src/app-static/main.js")
},
output: {
path: builtRoot,
filename: "[name]-[fullhash].js",
// https://stackoverflow.com/a/36308143/1954789
publicPath: webBuildRoot
},
resolve: {
extensions: [".ts", ".js", ".tsx"]
},
devtool: isDebug ? "eval" : false,
optimization: {
// https://webpack.js.org/configuration/optimization/#optimizationmoduleids
moduleIds: "deterministic"
// runtimeChunks: "single"
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, "legacy/app-old/index.html"),
filename: path.join(builtRoot, "ng1x.html"),
inject: "head",
xhtml: true,
chunks: ["ng1x"]
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, "src/app-static/index.html"),
filename: path.join(webRoot, "index.html"),
inject: "head",
xhtml: true,
chunks: ["static"]
})
],
module: {
rules: [
// {
// test: /\.css$/,
// type: "asset/inline"
// },
{
test: /\.css$/,
use: [
{
loader: "style-loader"
},
{
loader: "css-loader"
}
]
},
{
test: /\.(eot|svg|ttf|woff|woff2|png|svg|jpg|gif)$/,
type: "asset"
},
{
test: /\.tsx?/,
use: [{ loader: "ts-loader" }]
}
]
}
};