Installation
Install the package​
npm install docxio
# or
bun add docxio
Configure TypeScript​
Add the JSX import source to your tsconfig.json:
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "docxio"
}
}
This tells TypeScript to use docxio's JSX factory instead of React's. No React dependency is needed.
Backend selection​
docxio ships with three WASM backends. The default "auto" mode works for most projects.
| Backend | WASM Size | ZIP handling | Best for |
|---|---|---|---|
"minimal" | 441 KB | JS-side (@docxio/zip) | Browser -- smallest bundle |
"full" | 920 KB | Rust-side | Server -- includes parser, template engine, validator |
"auto" (default) | -- | -- | Tries minimal first, falls back to full |
To force a specific backend:
import { render } from "docxio";
const bytes = await render(doc, { backend: "minimal" });
Optional packages​
Install additional packages depending on your use case:
| Package | Purpose |
|---|---|
@docxio/html | HTML and Markdown export |
@docxio/bun | Bun build plugin |
@docxio/node | Native Node.js bindings via napi-rs |
@docxio/zip | JS-side ZIP assembly (used by minimal backend) |
@docxio/wasm-minimal | Minimal WASM binary (XML only) |
# Example: add HTML export
npm install @docxio/html
Verify installation​
Create a file called hello.tsx and run it:
/** @jsxImportSource docxio */
import { render } from "docxio";
const doc = (
<document title="Test">
<section>
<paragraph><run>It works!</run></paragraph>
</section>
</document>
);
const bytes = await render(doc);
console.log(`Generated ${bytes.length} bytes`);