Arika d12330afd6 Implementation for automatically reading optional files
It automatically reads riotrc, riotrc.js, riot.config.js file and
applies it.
2019-02-23 14:19:36 +09:00

28 lines
622 B
JavaScript

const { compile } = require('riot-compiler');
const { Asset } = require('parcel-bundler');
const preamble = "const riot = require('riot');\n";
class RiotAsset extends Asset {
constructor(name, options) {
super(name, options);
this.type = 'js';
}
async generate() {
const riotOpts = (await this.getConfig(['.riotrc', '.riotrc.js', 'riot.config.js'])) || {};
let code = compile(this.contents, riotOpts, this.name);
code = `${ preamble }${ code }`;
this.contents = code;
return [
{
type: 'js',
value: this.contents
}
];
}
}
module.exports = RiotAsset;