liveBook · Manning

Template compiler

As explained in Build a Frontend Web Framework (From Scratch)

A compiler that transforms component templates into JavaScript code capable of creating the component view in a browser.

A template compiler transforms each component’s template into JavaScript code that runs in the browser and creates the component’s view. It is one step in the frontend build process, before application code is bundled for deployment. section 1.3.1

The compiler’s practical responsibilities are:

  • Process the template belonging to each component. section 1.3.1
  • Produce JavaScript that creates the component view in the browser. section 1.3.1
  • Feed the resulting application code into later bundling steps, such as app.bundle.js. section 1.3.1

Conditional templates

A template may contain conditional markup, such as a paragraph shown only when hasDiscount is true. Different frameworks express that condition with different template forms, but the compiler turns the component template into browser-executable JavaScript. section 1.3.1

<p v-if="hasDiscount">
  You get a discount!
</p>

Compare conditional template syntax with the equivalent forms used by other frontend frameworks. section 1.3.1

How Build a Frontend Web Framework (From Scratch) covers it

How deep it goes
Defines the compiler’s input and output within the build pipeline but stops short of explaining parsing or code-generation internals.
Examples
Uses conditional markup and identifies app.bundle.js among the resulting build artifacts.
What you can do after
Evaluate/understand where template transformation fits in a framework’s frontend build and deployment process.
How it connects
Connects component templates with JavaScript, browser rendering, bundling, and frontend application builds.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Frontend Web Framework (From Scratch). The section links point to the parts of the book it draws on.