Pre-compilation on gives you following benefits:

    • Ability to compile tags with your .
    • Big performance benefit. No need to load and execute the compiler on browser.
    • Sourcemaps support for debugging.

    Tools like and are the perfect match to bundle your riot application tags.For such tools we provide riot official loaders to let import natively riot components into your source code:

    • webpack
    • parcel
    • With the riot loaders your application entry script might look like this:
    1. import {compile} from '@riotjs/compiler'
    2. const { code, map } = compile('<p>{hello}</p>', {
    3. //...options
    4. file: 'my/path/to/my-component.riot',
    5. // transform the `:host` css rules
    6. scopedCss: true,
    7. // expressions delimiters
    8. brackets: ['{', '}'],
    9. // keep HTML comments
    10. })

    The compile function takes a string and returns an object containing the code and map keys.You can handle the code generated however you like and use it into your build system.

    Remember that the riot compiler outputs javascript modules and you might want to transpile them in your bundle.

    1. npm install @riotjs/cli -g

    Using

    Here is how riot command works:

    1. # compile a file to current folder
    2. riot some.riot
    3. # compile file to target folder
    4. riot some.riot --output some-folder
    5. # compile file to target path
    6. # compile all files from source folder to target folder
    7. riot some/folder --output path/to/dist

    For more information, type: riot —help

    Watch mode

    You can watch directories and automatically transform files when they are changed.

    Custom extension

    You’re free to use any file extension for your tags (instead of default .riot):

    1. riot --extension html

    ES6 Config file

    1. riot --config riot.config src

    The riot riot.config.js file:

    1. export default {
    2. output: 'tags/dist',
    3. // sourcemap type
    4. sourcemap: 'inline',
    5. // files extension
    6. extension: 'foo'
    7. }

    If you want to use custom preprocessors in your project you should install @riotjs/cli as devDependency running it via npm scripts as follows:

    That’s how your riot.config.js file might look like in case you want to use pug as components template engine

    1. import { registerPreprocessor } from '@riotjs/compiler'
    2. import { render } from 'pug'
    3. // register the pug preprocessor
    4. const { file } = options
    5. return {
    6. code: render(code, {
    7. filename: file,
    8. pretty: true,
    9. doctype: 'html'
    10. })
    11. }
    12. })
    13. export default {
    14. extension: 'pug',
    15. // assign the pug preprocessor to the riot compiler options
    16. riot: {
    17. template: 'pug'
    18. }
    19. }

    Build your whole application

    You can also use the CLI to bundle your entire application.

    1. import {component} from 'riot'
    2. import App from './app.riot'
    3. component(App)(document.getElementById('root'))

      Your file will contain all the Riot.js components imported in your application and the code to run it.