File size: 2,297 Bytes
bee6636
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { defineConfig } from "@rspack/cli";
import { rspack } from "@rspack/core";
import { RsdoctorRspackPlugin } from "@rsdoctor/rspack-plugin";
import { TsCheckerRspackPlugin } from "ts-checker-rspack-plugin";

import { readFile } from "node:fs/promises";
import { execSync } from "node:child_process";
import { join } from "path";
import { fileURLToPath } from "url";
const __dirname = fileURLToPath(new URL(".", import.meta.url));
const packagemeta = JSON.parse(await readFile("package.json"));

export default defineConfig({
	mode: "development",
	devtool: "source-map",
	entry: {
		all: join(__dirname, "src/entry.ts"),
		// shared: join(__dirname, "src/shared/index.ts"),
		// worker: join(__dirname, "src/worker/index.ts"),
		// client: join(__dirname, "src/client/index.ts"),
		// controller: join(__dirname, "src/controller/index.ts"),
		sync: join(__dirname, "src/sync.ts"),
	},
	resolve: {
		extensions: [".ts", ".js"],
	},
	module: {
		rules: [
			{
				test: /\.ts$/,
				loader: "builtin:swc-loader",
				exclude: ["/node_modules/"],
				options: {
					jsc: {
						parser: {
							syntax: "typescript",
						},
						target: "es2022",
					},
					module: {
						type: "es6",
						strict: false,
						strictMode: false,
					},
				},
				type: "javascript/auto",
			},
		],
		parser: {
			javascript: {
				overrideStrict: "non-strict",
				dynamicImportMode: "eager",
			},
		},
	},
	output: {
		filename: "scramjet.[name].js",
		path: join(__dirname, "dist"),
		libraryTarget: "es2022",
		iife: true,
	},
	plugins: [
		new TsCheckerRspackPlugin(),
		new rspack.ProvidePlugin({
			dbg: [join(__dirname, "src/log.ts"), "default"],
		}),
		new rspack.DefinePlugin({
			VERSION: JSON.stringify(packagemeta.version),
		}),
		new rspack.DefinePlugin({
			COMMITHASH: (() => {
				try {
					const hash = JSON.stringify(
						execSync("git rev-parse --short HEAD", {
							encoding: "utf-8",
						}).replace(/\r?\n|\r/g, "")
					);

					return hash;
				} catch {
					return "unknown";
				}
			})(),
		}),
		process.env.DEBUG
			? new RsdoctorRspackPlugin({
					supports: {
						parseBundle: true,
						banner: true,
					},
				})
			: null,
	],
	target: "webworker",
});