Skip to content

Latest commit

 

History

History
126 lines (69 loc) · 3.24 KB

javascript-api.md

File metadata and controls

126 lines (69 loc) · 3.24 KB

JavaScript API

require('lasso')

Methods

configure(config)

Configures the default lasso instance using the provided config. The config can either be an object or a path to a JSON file.

create(config)

Creates a new configured Lasso instance.

getDefaultLasso()

Returns the default Lasso instance.

lassoPage(options, callback)

Equivalent to require('lasso').getDefaultLasso().lassoPage(options, callback). See Lasso » lassoPage below.

lassoResource(pageConfig, callback)

Equivalent to require('lasso').getDefaultLasso().lassoResource(options, callback). See Lasso » lassoResource below.

require('lasso/middleware')

serveStatic(options)

Express middleware to serve up static files generated by Lasso.js.

Example usage:

app.use(require('lasso/middleware').serveStatic());
  • Supported options:
    • lasso - The configured lasso instance (defaults to require('lasso').getDefaultLasso())
    • sendOptions - Options passed to the send module that is used to serve up static assets

Config

See ./lib/Config.js

Lasso

Methods

lassoPage(options, callback)

Processes all of the dependencies for a page to produce a set of static JS and CSS bundles, as well as any other static assets.

The result will be a LassoPageResult instance that provides the list of generated URLs for all of the static bundles, as well as a list of the generated files.

Supported options:

  • dependencies - An array of dependencies
  • from - The base directory for calculating relative paths (optional)
  • packagePath - A path to a browser.json file
  • packagePaths - An array of paths to browser.json files

lassoResource(options, callback)

Properties

config

The loaded Config config instance

LassoPageResult

Methods

getBodyHtml()

Short-hand for lassoPageResult.getHtmlForSlot('body').

getCSSFiles()

Returns an array of all of file paths for all of the generated JavaScript bundles

getCSSUrls()

Returns an array of all of URLs for all of the generated CSS bundles

getHeadHtml()

Short-hand for lassoPageResult.getHtmlForSlot('head').

getHtmlBySlot()

Returns the HTML markup for each slot. The returned object will be an object. For each property of the returned object, the name will be the slot name (e.g. head) and the value will be the HTML markup (e.g. <link rel="stylesheet" type="text/css" href="static/style.less.css">).

getHtmlForSlot(slotName)

Example usage:

var headHtml = lassoPageResult.getHtmlForSlot('head');
var bodyHtml = lassoPageResult.getHtmlForSlot('body');

getJavaScriptFiles()

Returns an array of all of file paths for all of the generated JavaScript bundles

getJavaScriptUrls()

Returns an array of all of URLs for all of the generated JavaScript bundles

getOutputFiles()

Returns an array of all of file paths for all of the generated files