Webpack loader for rendering plain HTML from EJS template files
Install with npm. And be sure to install EJS and Webpack, which are peer dependencies.
npm install --save-dev webpack ejs ejs-html-loader
In your Webpack configuration, options and locals can be passed to EJS in two ways. First, through a query string or query object:
module.exports = {
// ...
module: {
loaders: [{
test: /\.ejs$/,
loader: 'ejs-html?title=The%20Big%20Gatsby&production'
}]
}
};
Or second, via an 'ejsHtml'
property:
module.exports = {
// ...
ejsHtml: {
title: 'For Whom the Bell Rings',
baseUrl: '/',
delimiter: '?'
}
};
All properties passed to the loader will be available to your templates as local variables. In addition, the following EJS options may be set:
-
context :
object
The value ofthis
in your templates. If specified, its properties will be available in your templates, e.g.<%= this.somePropery %>
. -
delimiter :
string='%'
Character used inside of angle brackets marking opening/closing tags. Defaults to'%'
, as in<%= some.variable %>
.
The EJS filename
option is set automatically, so you may include partials
relative to your template files. If you want your included files to
automatically recompile in watch mode, be sure to use the following syntax:
<% include some/file %>
Copyright © 2016 Akim McMath. Licensed under the MIT License.