Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/react/transform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@
"scripts": {
"bench": "vitest bench",
"build:debug": "napi build --platform --js index.cjs",
"build:wasm": "node ./scripts/build_wasm.js",
"build:wasm": "rslib build",
"test": "vitest --coverage",
"test:cargo": "cargo test"
},
"devDependencies": {
"@emnapi/core": "1.3.1",
"@emnapi/runtime": "1.3.1",
"@napi-rs/cli": "2.18.4",
"esbuild": "^0.27.3",
"tiny-glob": "0.2.9"
}
}
79 changes: 79 additions & 0 deletions packages/react/transform/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { defineConfig, type RsbuildPlugin } from '@rslib/core';
import { execSync } from 'node:child_process';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const root = __dirname;

const pluginCargoBuild = {
name: 'plugin-cargo-build',
setup(api) {
api.onBeforeBuild(() => {
execSync(
`cargo build --release --target wasm32-unknown-unknown --features noop`,
{
env: {
...process.env,
RUSTFLAGS: '-C link-arg=--export-table -C link-arg=-s --cfg getrandom_backend="custom"',
},
stdio: 'inherit',
cwd: root,
},
);
});
},
} satisfies RsbuildPlugin;

export default defineConfig({
lib: [
{
format: 'cjs',
syntax: 'es2022',
dts: false,
},
],
source: {
entry: {
wasm: './src/wasm.js',
},
},
output: {
target: 'node',
distPath: {
root: './dist',
},
cleanDistPath: false,
filename: {
js: '[name].cjs',
},
},
plugins: [pluginCargoBuild],
tools: {
rspack: {
resolve: {
alias: {
'#react_transform.wasm': path.resolve(
root,
'../../../target/wasm32-unknown-unknown/release/react_transform.wasm',
),
},
},
resolveLoader: {
alias: {
'buffer-loader': path.resolve(__dirname, 'scripts/buffer-loader.cjs'),
},
},
module: {
rules: [
{
test: /\.wasm$/,
use: ['buffer-loader'],
type: 'javascript/auto',
},
],
},
},
},
});
7 changes: 7 additions & 0 deletions packages/react/transform/scripts/buffer-loader.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2026 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.
module.exports = function loader(content) {
return `export default Buffer.from("${content.toString('base64')}", "base64");`;
};
module.exports.raw = true;
54 changes: 0 additions & 54 deletions packages/react/transform/scripts/build_wasm.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/react/transform/src/wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getDefaultContext } from '@emnapi/runtime';

// build with `./node_modules/.bin/esbuild src/wasm.js --bundle --loader:.wasm=binary --format=cjs --platform=neutral --outfile=dist/wasm.js`
// eslint-disable-next-line import/no-unresolved
import bytes from '../dist/react_transform.wasm';
import bytes from '#react_transform.wasm';
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

const mod = new WebAssembly.Module(bytes);

Expand Down
3 changes: 2 additions & 1 deletion packages/react/transform/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"src/wasm.js",
"build.rs",
"Cargo.toml",
"scripts/build_wasm.sh"
"rslib.config.ts",
"scripts/buffer-loader.cjs"
],
"outputs": ["dist/wasm.cjs"]
},
Expand Down
Loading
Loading