UNPKG

rollup-plugin-hbsidom

Version:

A Rollup plugin for transforming handlebars templates to incremental-dom.

26 lines (21 loc) 686 B
import { createFilter } from 'rollup-pluginutils'; import hbsCompiler from 'handlebars-idom'; export default function (options = {}) { const filter = createFilter( options.include || [ '**/*.hbs', '**/*.handlebars', '**/*.mustache' ], options.exclude || 'node_modules/**' ); const sourceMap = options.sourceMap !== false; return { transform (code, id) { if(!filter(id)) return; let compiled = "import * as IncrementalDOM from 'incremental-dom';\n"; compiled += "export default function(data) {\n"; compiled += hbsCompiler.compile(code) + "};\n"; return { code: compiled, map: { mappings: '' } }; } }; };