Skip to content

CSS JS Processor Interface

Jun Yang edited this page Jun 5, 2016 · 2 revisions

CSS/JS processors can be used to pre-compile stylesheets and JavaScripts in Brick.JS.

To enable your processor, the processor instance should be registered into brick-asset. See: https://github.com/brick-js/brick-asset/blob/master/index.js That means a pull-request to brick-asset/index.js is needed.

Registration

Processors are registered for specific file extensions. It's possible for a processor instance to be registered for multiple file extensions.

// file: brick-asset/index.js
var processor = ...
Processor.register('.less', processor, root);

The registration of CSS and JS processors are the same.

CSS Processor Instance

The processor instance registered above should be an Object with .render() method:

Promise<String> processor.render(path, classPrefix)

The .render() should accept the CSS source file path, the intended classPrefix given by Brick.JS, and return a Promise that resolve as the result CSS String.

The default CSS Processor is: https://github.com/brick-js/brick-asset/blob/master/processor/css.js

JavaScript Processor Instance

The processor instance registered as a JavaScript processor should also be an Object with .render() method:

Promise<String> processor.render(path, moduleId)

The processor shall accept the script path, current moduleId, and return a Promise that resolves as the result JavaScript String.

The default JavaScript Processor is: https://github.com/brick-js/brick-asset/blob/master/processor/js.js

Available Processors

Now available processors:

Clone this wiki locally