fig.js component compiler
obj = compiler(input[, opts])
input is a string a of fig component. Available options for the
opts object are as follows:
opts.filePath- required if you want to use pug's relative includes/extends inside of the component
opts.defaultName- name set for the component, if the
labelis missing on the component
opts.debug- if set to
compileDebugto pug, tldr: if
falseoutput is smaller, at the cost of some pretty error messages
obj which has a few properties:
obj.template- a function compiled by pug that takes a locals object and spits out HTML when asked to
obj.style- just a string containing the contents of the style tag inside the component
obj.script- string of code which just so happens to be ran through
es-2015preset for your dearest convenience.
obj.name- name of the component, taken from the
opts.defaultNameif that doesn't exist. Otherwise
For development pleasure, this module includes a simple connect middleware function, compatible with express. Used akin to
express.static middleware, point it to the directory you store your fig components in, the middleware should compile the component on the fly (without caching) and serve it to the client.
⚠️ Not meant to be used in production.
// server.jsconst express =const fig =const app =appapp// client.jsconst app =app // pulls from localhost:3000/main-view.figapp_components // should be the compiled component
npm install fig-compiler --save