marko-js / marko

A declarative, HTML-based language that makes building web apps fun
https://markojs.com/
MIT License
13.37k stars 644 forks source link

Compiler API Docs #827

Closed callumlocke closed 3 years ago

callumlocke commented 7 years ago

I want to compile Marko programatically, not using a CLI. Is there any documentation for this?

patrick-steele-idem commented 7 years ago

require('marko/compiler') has a compileFile (for compiling a template for running on the server) and a compileFileForBrowser (for compiling a template for running in the browser). You can see their usage here. If you would like more details please let us know. The compiler API is simple, but not fully documented at the moment.

patrick-steele-idem commented 7 years ago

Also, for reference: https://github.com/marko-js/marko/blob/master/src/compiler/index.js

balupton commented 5 years ago

a compileFile (for compiling a template for running on the server) and a compileFileForBrowser (for compiling a template for running in the browser).

What is the difference between the targets? How does the target change the output?

DylanPiercey commented 5 years ago

@balupton output: "html" compiles to template to write to an html output stream like the response object in node js.

output: "vdom" is for use in the browser and compiles the template to render to a virtual dom which is then diffed to calculate the patches to the dom needed across renders.

You can see the difference by using the markoc command (that ships with Marko).

# Compile a template with output "html"
markoc ./my-template.marko
# Compile a template with output "vdom"
markoc ./my-template.marko --vdom
SacDin commented 5 years ago

I want to compile a required component having dependencies already compiled in in-memory variables. Is it possible to pass dependency components this way ?

DylanPiercey commented 3 years ago

https://markojs.com/docs/compiler/ (for Marko 5)