riot-compiler

raw JSON →
3.6.0 verified Fri May 01 auth: no javascript

Compiler for Riot.js .tag files, transforming custom tag syntax (HTML + JavaScript) into standard JavaScript modules. Current stable version is 10.0.1 (2024), with major breaking changes in v10.0.0: dropped Node <22, switched from `assert` to `with` for JSON imports, and changed boolean attribute handling on root nodes. v9.x series is in maintenance. Key differentiator: tightly coupled to Riot.js library, designed specifically for Riot's tag-based component model. Release cadence: irregular, with major versions tied to Riot.js updates.

error SyntaxError: Cannot use import statement outside a module
cause Trying to use ESM import in a CommonJS module without 'type': 'module' in package.json.
fix
Add "type": "module" to your package.json or rename file to .mjs.
error Error: The 'assert' option is deprecated. Please use 'with' instead.
cause Using old JSON import syntax with 'assert' in Node >=22.
fix
Replace assert { type: 'json' } with with { type: 'json' }.
breaking v10.0.0 drops support for Node.js <22 and removes CommonJS support.
fix Update Node.js version to >=22; ensure imports use ESM syntax.
breaking v10.0.0 changes boolean attribute handling on root nodes: attributes are no longer automatically set as properties.
fix Review component templates: use explicit attribute bindings or update Riot.js to latest.
breaking v10.0.0 switches JSON imports from 'assert' to 'with' syntax.
fix Update JSON import statements: replace `assert { type: 'json' }` with `with { type: 'json' }`.
deprecated v9.x is no longer actively maintained; security patches only.
fix Upgrade to v10.x for ongoing support.
npm install riot-compiler
yarn add riot-compiler
pnpm add riot-compiler

Compile a basic Riot.js .tag file with an ES module script tag.

import { compile } from 'riot-compiler';
const code = compile(`<my-tag>\n  <p>{ message }</p>\n  <script>\n    export default {\n      message: 'Hello'\n    }\n  </script>\n</my-tag>`);
console.log(code);