{"id":19456,"library":"ejs-webpack-loader","title":"ejs-webpack-loader","description":"EJS template loader for webpack 4.x that compiles .ejs files into JavaScript template functions using the ejs library. Version 2.2.2 is the latest stable release, with no recent updates. It supports options like beautify, compileDebug, and htmlmin. Unlike ejs-loader or ejs-compiled-loader, this package is specifically designed for webpack 4 and avoids frontend dependencies. Useful for server-side rendering or generating HTML files with webpack.","status":"active","version":"2.2.2","language":"javascript","source_language":"en","source_url":"https://github.com/rorkflash/ejs-webpack-loader","tags":["javascript","ejs","webpack","loader","template"],"install":[{"cmd":"npm install ejs-webpack-loader","lang":"bash","label":"npm"},{"cmd":"yarn add ejs-webpack-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add ejs-webpack-loader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core template engine required at runtime to compile .ejs files.","package":"ejs","optional":false},{"reason":"Required only if the htmlmin option is set to true to minify HTML output.","package":"html-minifier","optional":true}],"imports":[{"note":"This package is a webpack loader, not a JavaScript module. It is used in webpack configuration under module.rules.","wrong":"const loader = require('ejs-webpack-loader')","symbol":"ejs-webpack-loader","correct":"import 'ejs-webpack-loader' // no import, used in webpack config"},{"note":"Pass options using the options object, not query string, to avoid deprecation warnings in webpack 4.","wrong":"rule.loader = 'ejs-webpack-loader?data=...'","symbol":"default export","correct":"rule.use = [{ loader: 'ejs-webpack-loader', options: { data: {...}, htmlmin: true } }]"},{"note":"Use inline loader syntax (!!) with HtmlWebpackPlugin or for direct require.","wrong":"import template from './file.ejs' // without loader prefix","symbol":"template function","correct":"import template from '!!ejs-webpack-loader!./file.ejs'; // returns function"}],"quickstart":{"code":"// webpack.config.js\nconst path = require('path');\nmodule.exports = {\n  entry: './src/index.js',\n  output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist') },\n  module: {\n    rules: [{\n      test: /\\.ejs$/,\n      use: [{ loader: 'ejs-webpack-loader', options: { data: { title: 'Hello', someVar: 'World' }, htmlmin: true } }]\n    }]\n  }\n};","lang":"javascript","description":"Webpack configuration using ejs-webpack-loader to compile .ejs templates with data and HTML minification."},"warnings":[{"fix":"Pass all variables under the 'data' property in the loader options.","message":"EJS data must be passed via the 'data' option, not directly in the template. The template cannot access webpack variables like __dirname.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use extract-loader or HtmlWebpackPlugin to output HTML, or call the returned function in your code.","message":"The loader returns a function, not a string. To get rendered HTML, you must call the function with data (or use separate extractors like file-loader or HtmlWebpackPlugin).","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use the 'options' property in the rule as shown in the quickstart.","message":"Webpack 4 loader query string options (e.g., 'ejs-webpack-loader?htmlmin=true') are deprecated in favor of the 'options' object.","severity":"deprecated","affected_versions":"<2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Add a rule with ejs-webpack-loader as shown in the quickstart.","cause":"Missing or misconfigured rule for .ejs files in webpack config.","error":"Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type."},{"fix":"Run 'npm install ejs-webpack-loader --save-dev'","cause":"Package not installed or not in node_modules.","error":"Error: Could not find loader 'ejs-webpack-loader'"},{"fix":"Call the imported template function with data: template({ title: '...' })","cause":"Using the exported function as a string without calling it.","error":"TypeError: template is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}