npm.io
0.1.27 • Published 10 months ago

@mlc-ai/web-xgrammar

Licence
Apache-2.0
Version
0.1.27
Deps
0
Size
2.3 MB
Vulns
0
Weekly
0
Stars
2.0K

web-xgrammar

This folder contains the source code and emcc bindings for compiling XGrammar to Javascript/Typescript via emscripten.

Build from source

  1. Install emscripten. It is an LLVM-based compiler that compiles C/C++ source code to WebAssembly.

    • Follow the installation instruction to install the latest emsdk.
    • Source emsdk_env.sh by source /path/to/emsdk_env.sh, so that emcc is reachable from PATH and the command emcc works.
    • We can verify the successful installation by trying out emcc in the terminal.
  2. Modify the content of cmake/config.cmake to be web/config.cmake.

  3. Run the following

    source /path/to/emsdk_env.sh
    npm install
    npm run build

Example

To try out the test webpage, run the following

cd example
npm install
npm start
Testing

For testing in node environment, run:

npm test

Keywords