[![Build Status][ci-image]][ci-url] [![Issue Count][codeclimate-image]][codeclimate-url] [![Coverage Status][coverage-image]][coverage-url] [![NPM version][npm-version-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-url] [![MIT License][license-image]][license-url] ## Important This compiler will not work with older Riot.js versions. It's designed to work with Riot.js > 4.0.0. For Riot.js < 4.0.0 please check the [v3](https://github.com/riot/compiler/tree/v3) branch ## Installation ``` npm i @riotjs/compiler -D ``` ## Usage The riot compiler can compile only strings: ```js import { compile } from '@riotjs/compiler' const { code, map } = compile('
{hello}
') ``` You can compile your tags also using the new `registerPreprocessor` and `registerPostprocessor` APIs for example: ```js import { compiler, registerPreprocessor, registerPostprocessor } from '@riotjs/compiler' import pug from 'pug' import buble from 'buble' // process your tag template before it will be compiled registerPreprocessor('template', 'pug', function(code, { options }) { const { file } = options console.log('your file path is:', file) return { code: pug.render(code), // no sourcemap here map: null } }) // your compiler output will pass from here registerPostprocessor(function(code, { options }) { const { file } = options console.log('your file path is:', file) // notice that buble.transform returns {code, map} return buble.transform(code) }) const { code, map } = compile('{hello}
', { // specify the template preprocessor template: 'pug' }) ``` ## API ### compile(string, options) #### @returns `{ code, map }` output that can be used by Riot.js - *string*: is your tag source code - *options*: the options should contain the `file` key identifying the source of the string to compile and the `template` preprocessor to use as string Note: specific preprocessors like the `css` or the `javascript` ones can be enabled simply specifying the `type` attribute in the tag source code for example ```html