-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
86 lines (83 loc) · 2.29 KB
/
webpack.config.ts
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
import fs from "fs";
import path from "path";
import chalk from "chalk";
import webpack from "webpack";
import download from "download";
import { execSync } from "child_process";
import HtmlWebpackPlugin from "html-webpack-plugin";
import ShellPlugin from "webpack-shell-plugin-next";
const isProduction = process.env.NODE_ENV == "production";
const arch = process.env.ARCH || "amd64"; // can be arm64
const version = process.env.VERSION || "v0.6.3"; // https://github.com/ktock/container2wasm/releases
const url = `https://github.com/ktock/container2wasm/releases/download/${version}/container2wasm-${version}-linux-${arch}.tar.gz`;
const container = "debian:bookworm-slim";
const config: webpack.Configuration = {
entry: "./src/index.ts",
output: {
clean: true,
path: path.resolve(__dirname, "dist"),
},
devServer: {
open: true,
host: "localhost",
},
bail: isProduction,
plugins: [
new HtmlWebpackPlugin(),
new ShellPlugin({
safe: true,
onBeforeBuild: {
blocking: true,
parallel: false,
scripts: [
async () => {
if (fs.existsSync("bin/c2w")) return;
console.log(chalk.bgYellowBright(`Downloading ${url}`));
await fs.promises.mkdir("bin", { recursive: true });
await download(url, "bin", { extract: true });
},
() => {
if (fs.existsSync("bin/brocess.wasm")) return;
console.log(chalk.bgYellowBright(`Generating brocess.wasm from ${container}`));
execSync("./bin/c2w --version");
execSync(`./bin/c2w ${container} bin/brocess.wasm`);
},
],
},
}),
],
experiments: {
futureDefaults: true,
syncWebAssembly: true,
asyncWebAssembly: true,
},
module: {
rules: [
{
test: /\.(ts|tsx)$/i,
loader: "ts-loader",
exclude: ["/node_modules/"],
options: {
transpileOnly: true,
},
},
{
test: /\.wasm$/i,
type: "webassembly/async",
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".jsx", ".js", ".json"],
},
externals: {
wasi_snapshot_preview1: "WASI",
},
performance: {
hints: false,
},
};
module.exports = () => ({
mode: isProduction ? "production" : "development",
...config,
});