
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@groveco/ejs-loader
Advanced tools
EJS (Underscore/LoDash Templates) loader for webpack compiled as an ECMAScript module. Uses lodash template function to compile templates.
If you are looking for the loader which uses EJS templating engine, there is ejs-compiled-loader
npm install @groveco/ejs-loader
import template from '@groveco/ejs-loader?variable=data!./file.ejs';
// => returns the template function compiled with undesrcore (lodash) templating engine.
// And then use it somewhere in your code
template(data) // Pass object with data
The variable option is required
to compile EJS templates into ES compatible modules. If the variable
option is not provided as a loader or query
option, an UnsupportedConfiguration
Exception will be thrown throw. Please see https://github.com/lodash/lodash/issues/3709#issuecomment-375898111 for additional details
You also should provide a global _
variable with the lodash/underscore runtime. You can do it with the following webpack plugin: https://github.com/webpack/docs/wiki/list-of-plugins#provideplugin
plugins: [
new webpack.ProvidePlugin({
_: "underscore"
})
]
Underscore/Lodash options can be passed in using the querystring or adding an options block to your configuration.
Example config with Webpack 4+
module.exports = {
module: {
rules: [
{
test: /\.ejs$/,
loader: '@groveco/ejs-loader',
options: {
variable: 'data',
interpolate : '\\{\\{(.+?)\\}\\}',
evaluate : '\\[\\[(.+?)\\]\\]'
}
}
]
}
};
is equivalent to
var template = _.template('<%= template %>', { variable: 'data', interpolate : '\\{\\{(.+?)\\}\\}', evaluate : '\\[\\[(.+?)\\]\\]' });
Lodash template function does not provide include
method of ejs module. To include other templates, passing template functions as parameters does the job. For example:
index.js:
import mainTemplate from 'ejs!./main.ejs';
import hyperlinkTemplate from 'ejs!./hyperlink.ejs';
let renderedHtml = mainTemplate({ hyperlink: hyperlinkTemplate });
main.ejs:
<h1><%= hyperlink({ name: 'Example', url: 'http://example.com' }) %></h1>
hyperlink.ejs:
<a href="<%= url %>"><%= name %></a>
As a result, renderedHtml
becomes a string <h1><a href="http://example.com">Example</a></h1>
.
ejsLoader
or via loader's query
FAQs
EJS (Underscore/LoDash Templates) loader for webpack
We found that @groveco/ejs-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.