Skip to content

Commit

Permalink
Migrate to rsbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
encounter committed Dec 24, 2024
1 parent d171961 commit 8d5ed7c
Show file tree
Hide file tree
Showing 10 changed files with 576 additions and 3,740 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ rust/target/
.pnpm-debug.log
.cache/

data/*
!data/.empty
dist/*
!dist/.htaccess
data/
dist/
public/data/*
!public/data/.gitkeep

# wasm-pack not working correctly
pkg/index.js
16 changes: 4 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,14 @@
"private": true,
"license": "MIT",
"devDependencies": {
"@rspack/cli": "^1.1.3",
"@rspack/core": "^1.1.3",
"@rspack/dev-server": "^1.0.9",
"@swc/helpers": "^0.5.15",
"@swc/register": "^0.1.10",
"@rsbuild/core": "^1.1.12",
"@rsbuild/plugin-type-check": "^1.2.0",
"@types/node": "^22.9.3",
"@types/pngjs": "^6.0.5",
"@types/webxr": "^0.5.20",
"@webgpu/types": "^0.1.51",
"@xmldom/xmldom": "^0.9.5",
"buffer": "^6.0.3",
"clean-webpack-plugin": "^4.0.0",
"cross-env": "^7.0.3",
"fork-ts-checker-webpack-plugin": "^9.0.2",
"git-revision-webpack-plugin": "^5.0.0",
"html-webpack-plugin": "^5.6.3",
"onchange": "^7.1.0",
"pngjs": "^7.0.0",
"tsx": "^4.19.2",
Expand All @@ -33,8 +25,8 @@
"reflect-metadata": "^0.2.2"
},
"scripts": {
"start": "pnpm run build:rust && cross-env NODE_ENV=development rspack dev",
"build": "pnpm run build:rust && cross-env NODE_ENV=production rspack build",
"start": "pnpm run build:rust && rsbuild dev",
"build": "pnpm run build:rust && rsbuild build",
"build:rust": "wasm-pack build -t web rust",
"build:rust-dev": "wasm-pack build --dev -t web rust",
"build:ZeldaWindWaker": "cd src/ZeldaWindWaker/tools && tsx --experimental-wasm-modules zww_extractor.ts",
Expand Down
4,104 changes: 497 additions & 3,607 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

File renamed without changes.
Empty file added public/data/.gitkeep
Empty file.
63 changes: 63 additions & 0 deletions rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { defineConfig } from '@rsbuild/core';
import { pluginTypeCheck } from '@rsbuild/plugin-type-check';
import { execSync } from 'node:child_process';

let gitCommit = '(unknown)';
try {
gitCommit = execSync('git rev-parse --short HEAD').toString().trim();
} catch (e) {
console.warn('Failed to fetch Git commit hash', e);
}

export default defineConfig({
source: {
entry: {
index: './src/main.ts',
embed: './src/main.ts',
},
// Legacy decorators are used with `reflect-metadata`.
// TODO: Migrate to TypeScript 5.0 / TC39 decorators.
decorators: {
version: 'legacy',
},
define: {
__COMMIT_HASH: JSON.stringify(gitCommit),
},
},
html: {
template: './src/index.html',
},
output: {
target: 'web',
// Mark Node.js built-in modules as external.
externals: ['fs', 'path', 'url'],
// TODO: These should be converted to use `new URL('./file.wasm', import.meta.url)`
// so that the bundler can resolve them. In the meantime, they're expected to be
// at the root.
copy: [
{ from: 'src/**/*.wasm', to: '[name][ext]' },
{ from: 'node_modules/librw/lib/librw.wasm' },
],
},
// Enable async TypeScript type checking.
plugins: [pluginTypeCheck()],
tools: {
// Add a rule to treat .glsl files as source assets.
rspack(_config, { addRules }) {
addRules([
{
test: /\.glsl$/,
type: 'asset/source',
},
]);
},
// Disable standards-compliant class field transforms.
swc: {
jsc: {
transform: {
useDefineForClassFields: false,
},
},
},
},
});
111 changes: 0 additions & 111 deletions rspack.config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/Common/JSYSTEM/JPA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Endianness } from "../../endian.js";
import { GfxDevice, GfxInputLayout, GfxBuffer, GfxFormat, GfxVertexAttributeDescriptor, GfxVertexBufferFrequency, GfxBufferUsage, GfxBufferFrequencyHint, GfxIndexBufferDescriptor, GfxInputLayoutBufferDescriptor, GfxVertexBufferDescriptor } from "../../gfx/platform/GfxPlatform.js";
import { getPointHermite } from "../../Spline.js";
import { getVertexInputLocation, GX_Program } from "../../gx/gx_material.js";
import { Color, colorNewFromRGBA, colorCopy, colorNewCopy, White, colorFromRGBA8, colorLerp, colorMult, colorNewFromRGBA8 } from "../../Color.js";
import { type Color, colorNewFromRGBA, colorCopy, colorNewCopy, White, colorFromRGBA8, colorLerp, colorMult, colorNewFromRGBA8 } from "../../Color.js";
import { MaterialParams, ColorKind, DrawParams, fillIndTexMtx, fillTextureSize, fillTextureBias } from "../../gx/gx_render.js";
import { GXMaterialHelperGfx } from "../../gx/gx_render.js";
import { computeModelMatrixSRT, computeModelMatrixR, lerp, MathConstants, normToLengthAndAdd, normToLength, isNearZeroVec3, transformVec3Mat4w1, transformVec3Mat4w0, getMatrixAxisZ, setMatrixTranslation, setMatrixAxis, Vec3Zero, vec3SetAll } from "../../MathHelpers.js";
Expand Down
3 changes: 3 additions & 0 deletions src/rustlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ export async function loadRustLib() {

/*
if (typeof process !== 'undefined') {
// @ts-ignore
const fs = await import('fs');
// @ts-ignore
const path = await import('path');
// @ts-ignore
const url = await import('url');
const wasmPath = path.join(path.dirname(url.fileURLToPath(import.meta.url)), '../rust/pkg/noclip_support_bg.wasm');
const wasm = fs.readFileSync(wasmPath);
Expand Down
9 changes: 4 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"compilerOptions": {
"target": "es2017",
"target": "es2022",
"alwaysStrict": true,
"downlevelIteration": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noImplicitAny": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
Expand All @@ -16,15 +17,13 @@
"useDefineForClassFields": false,
"resolveJsonModule": true,
"lib": [
"es2017",
"es2019.array",
"es2021.string",
"esnext.BigInt",
"es2022",
"dom"
],
"sourceMap": true,
"moduleResolution": "Bundler",
"module": "ESNext",
"isolatedModules": true,
"types": [
"gl-matrix",
"webxr"
Expand Down

0 comments on commit 8d5ed7c

Please sign in to comment.