Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions .github/workflows/web-encoder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ jobs:
node-version: latest
cache: "npm"
cache-dependency-path: packages/json-encoder-web/package-lock.json
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown
override: true
- name: Install wasm-bindgen-cli
run: cargo install wasm-bindgen-cli --version "0.2.100"
- run: npm install
working-directory: packages/json-encoder-web
- run: npm run build
Expand Down
23 changes: 23 additions & 0 deletions packages/json-encoder-web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Dependencies
node_modules/

# Build outputs
dist/
pkg/
target/

# Logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Editor directories and files
.idea
.vscode
*.swp
*.swo
*~

# OS files
.DS_Store
Thumbs.db
44 changes: 44 additions & 0 deletions packages/json-encoder-web/build-wasm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env node
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');

function buildWasm() {
console.log('🔨 Building WASM module...');

// Clean previous build
if (fs.existsSync('pkg')) {
fs.rmSync('pkg', { recursive: true, force: true });
}
fs.mkdirSync('pkg');

try {
// Compile Rust to WASM
console.log('📦 Compiling Rust to WASM...');
execSync('cargo build --target wasm32-unknown-unknown --release', {
stdio: 'inherit'
});

// Generate bindings
console.log('🔗 Generating bindings...');
execSync(`wasm-bindgen \
target/wasm32-unknown-unknown/release/json_encoder_web.wasm \
--out-dir pkg \
--target bundler \
--no-typescript`, {
stdio: 'inherit'
});

console.log('✅ WASM build complete!');
} catch (error) {
console.error('❌ Build failed:', error.message);
process.exit(1);
}
}

// Run if called directly
if (require.main === module) {
buildWasm();
}

module.exports = { buildWasm };
2 changes: 1 addition & 1 deletion packages/json-encoder-web/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as wasm from './pkg';
import * as wasm from './pkg/json_encoder_web';
import * as copy from 'copy-to-clipboard';
import notie from 'notie';
import { editor as monacoEditor } from 'monaco-editor/esm/vs/editor/editor.api'
Expand Down
Loading