42 lines
847 B
JavaScript
42 lines
847 B
JavaScript
|
'use strict';
|
||
|
|
||
|
var pirates = require('pirates');
|
||
|
var compiler = require('@riotjs/compiler');
|
||
|
var core = require('@babel/core');
|
||
|
|
||
|
function compile(source, filename) {
|
||
|
const { code } = compiler.compile(source, { file: filename });
|
||
|
|
||
|
return core.transform(code, {
|
||
|
presets: [
|
||
|
[
|
||
|
'@babel/preset-env',
|
||
|
{
|
||
|
modules: 'cjs',
|
||
|
targets: {
|
||
|
node: process.versions.node
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
]
|
||
|
}).code
|
||
|
}
|
||
|
|
||
|
// returns the teardown function
|
||
|
function register(options) {
|
||
|
return pirates.addHook(compile,
|
||
|
{
|
||
|
exts: ['.riot'],
|
||
|
ignoreNodeModules: false,
|
||
|
...options
|
||
|
}
|
||
|
)
|
||
|
}
|
||
|
|
||
|
// autoregister the .riot file import if this file gets required without any explicit require call
|
||
|
if (typeof module !== 'undefined' && !module.parent) {
|
||
|
register();
|
||
|
}
|
||
|
|
||
|
module.exports = register;
|