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.
compile-ejs-loader
✓ import template from 'compile-ejs-loader!./file.ejs';
✗ const template = require('compile-ejs-loader!./file.ejs');
Only CommonJS require works in webpack config. In webpack 5, ESM imports are not supported for inline loader syntax; use `require`. This loader returns a compiled template function.
compile-ejs-loader (webpack config rule)
✓ module.exports = { module: { rules: [ { test: /\.ejs$/, loader: 'compile-ejs-loader' } ] } }
✗ module.exports = { module: { rules: [ { test: /\.ejs$/, use: 'compile-ejs-loader' } ] } }
Both `loader` and `use` work for single loaders. If using options, wrap with `{ loader: 'compile-ejs-loader', options: {} }`.
options
✓ options: { htmlmin: true, htmlminOptions: { removeComments: true } }
✗ options: { htmlmin: true, removeComments: true }
htmlmin option enables minification; additional minifier options must be placed under `htmlminOptions` key.
Shows webpack configuration using compile-ejs-loader with htmlmin, beautify options and inline require usage.
// webpack.config.js
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.ejs$/,
loader: 'compile-ejs-loader',
options: {
compileDebug: false,
beautify: true,
htmlmin: true,
htmlminOptions: {
removeComments: true,
collapseWhitespace: true
}
}
}
]
}
};
// src/index.js
const template = require('compile-ejs-loader!./template.ejs');
const html = template({ name: 'World' });
console.log(html);
Errors
Common errors & fixes
Module parse failed: Unexpected token (1:0) in file.ejs
Webpack is treating the .ejs file as raw text instead of using the loader.
fixAdd a rule for .ejs files: { test: /\.ejs$/, loader: 'compile-ejs-loader' } Cannot find module 'compile-ejs-loader'
Loader not installed or not in node_modules.
fixRun: npm install compile-ejs-loader --save-dev
You may need an appropriate loader to handle this file type.
Webpack missing rule for .ejs files.
fixAdd compile-ejs-loader rule in webpack config as shown in quickstart.
Template include 'templates/child' is not working; file not found.
Includes are resolved from webpack execution directory, not relative to template.
fixUse a path relative to the project root or set webpack context to your source directory.
Audit
Dependencies
webpackrequiredPeer dependency: requires webpack ^5.18.0 to function as a loader.