response.require
response.require is a root plugin, for compiling Javascript files using rex. It adds one method response.require
. Install using npm.
npm install responserequire
Usage
response.require
takes either a filename and an optional options object, or just the options object as first argument. The input can either be Javascript or HTML, and can be specified using options.html
or options.js
. When the input is determined to be HTML, either by checking the filename extension or options.html
, all the script tags which have the type attribute set to text/require
are extracted, joined and compiled using rex
.
var fs = ;var root = ;var responserequire = ; var app = ; app; app;
The module exposes an extra function which is mostly suited for development.
// Create a route and pass the script functionapp;
In a HTML file add a script tag whos src attribute points at the route. The specified script tags are compiled and inserted into the document.
<!-- ./index.html --> response.require test <!-- Type must be text/require, only script tags with that type will be compiled --> Hello
This is equivalent to doing the following on the server.
app;
responserequire.script
adds a more generic method of doing the above, which works with all HTML files, but requires multiple requests to the server.