2.0.1 • Published 7 years ago
subcode-loader v2.0.1
subcode-loader
Subcode template loader for webpack
Versions
Use any version below 2.0.0 for use with subcode below 3.0.0
Installation
npm install subcode subcode-loader
Configuration
// Example webpack rule for using this loader:
{
test: /\.html$/,
loader: 'subcode-loader',
options: {
// Available subcode compile options:
// - syntax
// - encoding
// - extend
// - async
// Function to wrap function code into a custom module:
wrap: function () {
}
}
}
Custom module code
Sometimes you want to wrap template function code into your own module code. See Function Code
{
options: {
wrap: function(code) {
// 'this' is the webpack loader context (that is already marked as async)
// 'escape-html' is used to escape template output.
this.callback(null, `
const __e = require('escape-html');
module.exports = ${code};
`);
}
}
}
Usage
A template module exports the render function as described here.
If the wrap options was specified, the module exports the code passed to the loader callback.
import myTemplate from './my-template.html';
const html = template(locals);