{"id":19454,"library":"ejs-compiled-loader","title":"ejs-compiled-loader","description":"Webpack loader that compiles EJS templates (without frontend dependencies) into reusable JavaScript functions. Current stable version is 3.1.0. Release cadence is irregular; major version bumps (e.g., 3.0.0) added webpack 4 support. Key differentiators: it strips out runtime dependencies, compiles templates to functions, supports HTML minification, and is intended for server-side or build-time template compilation—not for browser-ready templates with the full EJS runtime.","status":"active","version":"3.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/bazilio91/ejs-compiled-loader","tags":["javascript","ejs","webpack","loader","template","es6"],"install":[{"cmd":"npm install ejs-compiled-loader","lang":"bash","label":"npm"},{"cmd":"yarn add ejs-compiled-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add ejs-compiled-loader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"EJS library used to compile templates (peer dependency in v3).","package":"ejs","optional":false},{"reason":"Optional dependency for minifying HTML output (only needed if htmlmin is enabled).","package":"html-minifier","optional":true}],"imports":[{"note":"Webpack loader usage is identical in CommonJS and ESM; the loader returns the template function, not the raw source.","wrong":"const template = require('ejs-compiled-loader!./file.ejs');","symbol":"ejs-compiled-loader","correct":"import template from 'ejs-compiled-loader!./file.ejs';"},{"note":"webpack 4+ uses module.rules, not module.loaders. The loader property was deprecated in webpack 2.","wrong":"module.exports = { module: { loaders: [ { test: /\\.ejs$/, loader: 'ejs-compiled-loader' } ] } };","symbol":"rules config (webpack)","correct":"module.exports = { module: { rules: [ { test: /\\.ejs$/, use: 'ejs-compiled-loader' } ] } };"},{"note":"ejs-compiled-loader is a webpack loader; it cannot be used directly in Node without webpack.","wrong":"const template = require('ejs-compiled-loader!./file.ejs'); // Only works in webpack context","symbol":"require() in Node (without webpack)","correct":"const { compile } = require('ejs'); const template = compile(source);"}],"quickstart":{"code":"// webpack.config.js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.ejs$/,\n        use: 'ejs-compiled-loader'\n      }\n    ]\n  }\n};\n\n// app.js\nimport template from './file.ejs';\nconst html = template({ name: 'World' });\nconsole.log(html); // => '<p>Hello World</p>'","lang":"javascript","description":"Shows basic webpack configuration and how to import an .ejs template, then render it with data."},"warnings":[{"fix":"Upgrade to webpack 4+ or pin ejs-compiled-loader@2.3.0.","message":"ejs-compiled-loader v3 drops support for webpack <4. If you are on webpack 3 or earlier, use v2.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use module.rules with the use property instead of loaders.","message":"The module.loaders syntax is deprecated since webpack 2. Using it with ejs-compiled-loader will cause warnings.","severity":"deprecated","affected_versions":"*"},{"fix":"Example: use: 'ejs-compiled-loader?delimiter=?' or specify in options: use: { loader: 'ejs-compiled-loader', options: { delimiter: '?' } }","message":"EJS options like 'delimiter' or 'openDelimiter' are not directly supported in ejs-compiled-loader v3; you must pass them via query parameters or the options object.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Ensure you call the template function with data: const html = template(data);","message":"The loader returns a function, not a string. Attempting to assign the output directly to innerHTML will fail if not invoked.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run: npm install ejs","cause":"ejs is a peer dependency and must be installed separately.","error":"Module not found: Error: Can't resolve 'ejs' in '/path'"},{"fix":"Add a rule for .ejs files in your webpack configuration using ejs-compiled-loader.","cause":"Webpack cannot parse .ejs files without the ejs-compiled-loader configured.","error":"You may need an appropriate loader to handle this file type."},{"fix":"Call the imported template with data: const html = template(data);","cause":"You did not invoke the function returned by the loader.","error":"template is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}