Skip to content

NodeJS API

Roberto Asiel Guevara Castañeda edited this page Nov 27, 2019 · 1 revision

Nodejs API

const trebor = require('trebor');

const options = {
  extension: 'html', // the extension of html files (avaliable in `parseFile` method only).
  compilerOptions: {
    comments: true, // whether to create comment nodes or not.
    outDir: '.', // directory to put the generated files.
    minify: true, // whether to minify the generated code or not.
    moduleName: 'app', // name of resulting module and file.
    format: 'umd' // 'esm' | 'cjs' | 'iif'.
  },
  cssParser(source, options) { 
    return 'css'
  },
  htmlParser(source, options) { 
    return 'html'
  },
  jsParser(source, options) { 
    return 'js'
  },
  directives: [{
    attr: 'attribute-name', // without `$` sign.
    tools: '', // extra tools that you need.
    priority: 0, // order of directive parsing (lower value are parse first) 0 is the minimum value.
    action(node /* Element */, expression /* string */, segmts /* Segments */, parentVarName /* string */),
    reference: true, // set to true if the directive replace the node with a comment reference.
    walkChildren: false // set to false if the directive logic walk the child nodes of the node.
  }]
};

trebor.parseFile('./some-file' /* html file uri */, options /* options */);
const jscontent1 = trebor.parseSource('some html text' /* html text */, options /* options */);
Clone this wiki locally