Registry / devops / webpack-ejs3-loader

webpack-ejs3-loader

JSON →
library0.0.2jsnpmunverified

A webpack loader that compiles EJS templates into JavaScript functions at build time, with no frontend runtime dependencies. The current version 0.0.2 is a minor fork of compile-ejs-loader that upgrades dependencies and moves ejs, html-minifier, uglify-js, and loader-utils from devDependencies to dependencies for easier installation. It supports EJS compile options, optional HTML minification via html-minifier, and AST beautification via uglify-js. Works with webpack 4 and 5. Note that the package has very few downloads and may not receive updates.

npm install webpack-ejs3-loader
INSTALL
IMPORT
SIG · WEBPACK-EJS3-LOADE
W
webpack-ejs3-loader
devopsjavascriptv0.0.2
harness data pending
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);
Debug
Known issues
gotchaOptions like 'htmlmin' and 'beautify' must be passed via webpack's use.options object, not as query parameters in the inline loader string.
fix
Use the module.rules configuration with options object.
affects: *
deprecatedThe loader uses loader-utils, which is deprecated in webpack 5. In webpack 5, prefer using the built-in getOptions() from schema-utils.
fix
Consider switching to a more actively maintained EJS loader or using webpack 5's native options handling.
affects: >=5.0.0
gotchaWhen using inline loader syntax, the loader is applied before the file is resolved. Ensure the path is correct relative to webpack's context.
fix
Use absolute paths or resolve paths with path.resolve in webpack config.
affects: *
gotchaThe 'htmlmin' option requires html-minifier to be installed. If not, it silently fails or throws an error.
fix
Install html-minifier as a project dependency if using htmlmin: true.
affects: *
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.
fix
Run 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.
fix
Update 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.
fix
Validate the JSON or JavaScript object syntax in your webpack configuration.
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies
webpackrequiredpeer dependency required to function as a loader
Agent activity
8 hits · last 30 days
node
8
Resources
webpack-ejs3-loader — npm install webpack-ejs3-loader · libregistry