2019-08-03 09:27:50 -04:00

82 lines
2.1 KiB
Markdown

[![Build Status][travis-image]][travis-url]
[![NPM version][npm-version-image]][npm-url]
[![NPM downloads][npm-downloads-image]][npm-url]
[![MIT License][license-image]][license-url]
A parcel plugin for riot.js
## Important
If you are using Riot.js < 4.0.0 please check the [v3 branch](https://github.com/riot/parcel-plugin-riot/tree/v3)
## Using
Add parcel-plugin-riot to your project.
```bash
npm i -D @riotjs/parcel-plugin-riot @riotjs/compiler
```
-> You are ready!
```js
import App from './src/App.riot'
import {component} from 'riot'
component(App)(document.querySelector('#root'), {
message: 'Hello there'
})
```
## Configuration
If you want compile your tags using custom riot compiler options you can create a `riot.config.js` in the root folder of your project
```js
module.exports = {
hot: false // set it to true if you are using hmr
// add here all the other @riotjs/compiler options riot.js.org/compiler
// template: 'pug' for example
}
```
If you want to use `pug` as your template engine, your `riot.config.js` might look like this
```js
const { registerPreprocessor } = require('@riotjs/compiler')
const { render } = require('pug')
// register the pug preprocessor
registerPreprocessor('template', 'pug', (code, options) => {
const { file } = options
return {
code: render(code, {
filename: file,
pretty: true,
doctype: 'html'
})
}
})
module.exports = {
template: 'pug'
}
```
If you want to enable hmr via `hot` option you will need to install also [`@riotjs/hot-reload`](https://www.npmjs.com/package/@riotjs/hot-reload)
```bash
npm i @riotjs/hot-reload -D
```
[travis-image]: https://img.shields.io/travis/riot/parcel-plugin-riot.svg?style=flat-square
[travis-url]: https://travis-ci.org/riot/parcel-plugin-riot
[license-image]: https://img.shields.io/badge/license-MIT-000000.svg?style=flat-square
[license-url]: LICENSE
[npm-version-image]: https://img.shields.io/npm/v/@riotjs/parcel-plugin-riot.svg?style=flat-square
[npm-downloads-image]: https://img.shields.io/npm/dm/@riotjs/parcel-plugin-riot.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@riotjs/parcel-plugin-riot