Compiler API

The developer interface for the Ink compiler is designed to be expressive and easily access the Ink library in most scenarios. To create a new ink compiler you can follow the code below.

import ink from '@stackpress/ink'; const compiler = ink();

The ink() function itself takes in the following options, all of which are optional.

API: InkOptions

Property Returns Description
brand? string

The brand prefixed before the component tag name.

Example
const compiler = ink({ brand: 'ink' });
cwd? string

The project's current working directory (cwd).

Example
const compiler = ink({ cwd: '/path/to/project' });'
fs? FileSystem

The file system being used to read/write files.

Example
import fs from 'fs'; const compiler = ink({ fs });'
emitter? EventEmitter

The NodeJS EventEmitter instance being used.

Example
import emitter from 'events'; const compiler = ink({ emitter });'
minify? boolean

Whether to minify the generated JavaScript code.

Example
const compiler = ink({ minify: true });'
tsconfig? string

The location of the used tsconfig.json.

Example
const compiler = ink({ tsconfig: '/path/to/tsconfig.json' });'
extname? string

The component file extension.

Example
const compiler = ink({ extname: '.ink' });'

Calling ink() as in compiler = ink({/*options*/}) returns the Ink compiler which contains the following object.

API: InkCompiler

Property Returns Description
config Config

The Ink configuration

Example
compiler.config.brand; //--> 'ink'
fs FileSystem

The file system being used.

Example
compiler.fs.readFileSync('some/file', 'utf8');
emitter EventEmitter

The NodeJS EventEmitter instance being used.

Example
compiler.emitter.on('render', e => { console.log(e.params); });
manifest DocumentManifest

The manifest registry used to map build IDs to document entry files.

Example
compiler.manifest.entries();
component( ) Component
fromId( id: string ) DocumentBuilder

Returns a new DocumentBuilder instance given a build ID.

Example
compiler.fromId('abc123').build();
fromCache( cacheFile: string ) Build

Returns build information from a compiled template.

Example
compiler.fromCache('/path/to/build/abc123.js').document.render();
fromSource( sourceFile: string ) DocumentBuilder

Returns a new DocumentBuilder instance given a template source file.

Example
compiler.fromSource('./docs/api.ink').build();
use( options: Function ) InkCompiler

Enables a default build cache strategy.

Example
compiler.use(plugin)
asset( assetFile: string ) Asset

Returns a compiled build asset, given an asset file name.

Example
compiler.asset('abc123.css'); //--> { type: 'text/css', content: '...' }
client( sourceFile: string ) string

Returns a compiled client script, given the the template source file.

Example
compiler.client('./docs/api.ink'); //client script
import( sourceFile: string ) Build

Returns build information, given the the template source file.

Example
compiler.import('/path/to/build/abc123.js').document.render();
markup( sourceFile: string ) string

Returns a compiled markup, given the the template source file.

Example
compiler.markup('./docs/api.ink'); //--> <html>...</html>
render( sourceFile: string , props: Hash ) string

Returns the final HTML markup, given the the template source file.

Example
compiler.render('./docs/api.ink', { title: 'API Documentation' });
server( sourceFile: string ) string

Returns compiled server code, given the the template source file.

Example
compiler.server('./docs/api.ink'); // server script
styles( sourceFile: string ) string

Returns compiled css styles, given the the template source file.

Example
compiler.styles('./docs/api.ink'); //css styles