Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Pratyay360/upiqrcode/llms.txt

Use this file to discover all available pages before exploring further.

You may want to build upiqrcode from source if you need to customize the library, contribute a fix or feature, or test changes before they are published to npm. The build toolchain is straightforward: Rust handles the library code, and wasm-pack compiles it to WebAssembly and generates the JavaScript bindings and TypeScript types automatically.

Prerequisites

1

Install Rust

Install the Rust toolchain via rustup. This also installs cargo, the Rust package manager:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
After installation, restart your terminal or run source "$HOME/.cargo/env" to make the cargo and rustc commands available.
2

Install wasm-pack

Install wasm-pack, the tool that compiles Rust to WebAssembly and generates the npm-compatible output:
cargo install wasm-pack
Verify the installation:
wasm-pack --version
3

Clone the repository

Clone the source repository from GitHub:
git clone https://github.com/Pratyay360/upiqrcode
cd upiqrcode

Build commands

Run wasm-pack build with the --target flag that matches your intended environment. The build compiles the Rust library and writes the output to a pkg/ directory.
wasm-pack build --target bundler
TargetUse case
bundlerUse with Vite, webpack 5, or Rollup. The generated module uses import statements and relies on your bundler to load the .wasm file.
webDirect browser usage via <script type="module">. No bundler required; the .wasm file is fetched at runtime.
nodejsCommonJS output for use in Node.js scripts and servers.

Output: the pkg/ directory

After a successful build, wasm-pack creates a pkg/ directory with everything needed to publish or consume the package locally:
pkg
upiqrcode.js
upiqrcode_bg.wasm
upiqrcode.d.ts
upiqrcode_bg.wasm.d.ts
package.json
  • upiqrcode.js — JavaScript bindings that wrap the WASM exports, including the init default export and the named upiqrcode and svg_qr_code functions.
  • upiqrcode_bg.wasm — The compiled WebAssembly binary.
  • upiqrcode.d.ts — TypeScript type declarations, including the UpiqrcodeParams and UpiqrcodeResult interfaces.
  • package.json — Generated package metadata, ready to publish to npm or link locally.

Using your local build

You have two options for consuming the local build in another project. Option 1 — npm link: Register the local build as a globally linked package and then link it into your consuming project:
# In the upiqrcode/pkg directory
npm link

# In your consuming project
npm link upiqrcode
Option 2 — local path in package.json: Reference the pkg/ directory directly using a file: path:
package.json
{
  "dependencies": {
    "upiqrcode": "file:../upiqrcode/pkg"
  }
}
Then run npm install to symlink the dependency.

Running tests

The test suite uses wasm-bindgen-test, which runs in a headless browser. Make sure you have Firefox or Chrome installed:
wasm-pack test --headless --firefox

Release optimization

The Cargo.toml [profile.release] section sets opt-level = "s", which instructs the Rust compiler to optimize for binary size rather than speed. Additionally, wasm-opt runs with -Os during the wasm-pack release build, shrinking the .wasm file further. You do not need to change these settings for typical use.

Contributing

If you have fixed a bug or added a feature, open a pull request on GitHub:

upiqrcode on GitHub

Browse the source, open issues, and submit pull requests.

Next steps

API reference: upiqrcode()

See the full parameter reference, return type, and validation rules for the upiqrcode function.

Build docs developers (and LLMs) love