Compiling Templates to Javascript

The X compiler compiles your templates to vanilla javascript. There are several ways to compile your javascript templates. They can be compiled dynamically on the client in a browser, or on the server as a build process. We'll begin by looking at the compiler as an object, gradually looking to higher sophistication using node in order to precompile templates optionally as AMD modules.


The import statement depends on access to a file system. The way this is acheived is through node's filesystem API. When XforJS isn't running in a node environment, the import statement is disabled.


Compiled template files depend on reusable methods stored in an output library. The getLib method of the XforJS namespace returns the library that is needed by all compiled template files. You can include this seperately to reduce the overall size of compiled template files when the Compiler is configured accordingly.