Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default
✓ import template from 'webpack-ejs3-loader!./file.ejs';
✗ const template = require('webpack-ejs3-loader!./file.ejs');
The loader is used in webpack config or inline, not directly imported. This shows the import pattern when used with ECMAScript modules in webpack.
Rule.use.loader
✓ module.exports = { module: { rules: [ { test: /\.ejs$/, use: { loader: 'webpack-ejs3-loader', options: { htmlmin: true } } } ] } };
✗ module.exports = { module: { loaders: [ { test: /\.ejs$/, loader: 'webpack-ejs3-loader' } ] } };
Use the modern webpack rule configuration (use) instead of legacy loaders array.
Plugin template
✓ new HtmlWebpackPlugin({ template: 'webpack-ejs3-loader!./templates/index.ejs' })
✗ new HtmlWebpackPlugin({ template: './templates/index.ejs', loader: 'webpack-ejs3-loader' })
When using with HtmlWebpackPlugin, specify the loader inline in the template path.
Shows how to configure webpack-ejs3-loader in webpack config and use it both as a rule for .ejs files and inline with HtmlWebpackPlugin.
// webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
mode: 'development',
entry: './src/index.js',
output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js' },
module: {
rules: [
{
test: /\.ejs$/,
use: {
loader: 'webpack-ejs3-loader',
options: {
htmlmin: true,
htmlminOptions: { removeComments: true },
},
},
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: 'webpack-ejs3-loader!./src/template.ejs',
title: 'My App',
}),
],
};
// src/template.ejs
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
</head>
<body>
<h1>Hello, <%= name %>!</h1>
</body>
</html>
// src/index.js
const template = require('webpack-ejs3-loader!./template.ejs');
const html = template({ title: 'My App', name: 'World' });
console.log(html);
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'ejs'
ejs is a dependency but may not be installed if the package is not fully installed or if using a different package manager.
fixRun npm install ejs --save-dev to ensure ejs is available.
Module not found: Error: Can't resolve 'loader-utils'
Old versions of webpack-ejs3-loader may not declare loader-utils as a dependency; it was moved to dependencies in 0.0.2.
fixUpdate to version 0.0.2 or manually install loader-utils.
SyntaxError: Unexpected token '?' in JSON at position ...
Invalid JSON in webpack config options, e.g., extra comma.
fixValidate the JSON or JavaScript object syntax in your webpack configuration.
Audit
Dependencies
webpackrequiredpeer dependency required to function as a loader