ejs-compiled-loader

raw JSON →
3.1.0 verified Sat Apr 25 auth: no javascript

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.

error Module not found: Error: Can't resolve 'ejs' in '/path'
cause ejs is a peer dependency and must be installed separately.
fix
Run: npm install ejs
error You may need an appropriate loader to handle this file type.
cause Webpack cannot parse .ejs files without the ejs-compiled-loader configured.
fix
Add a rule for .ejs files in your webpack configuration using ejs-compiled-loader.
error template is not a function
cause You did not invoke the function returned by the loader.
fix
Call the imported template with data: const html = template(data);
breaking ejs-compiled-loader v3 drops support for webpack <4. If you are on webpack 3 or earlier, use v2.
fix Upgrade to webpack 4+ or pin ejs-compiled-loader@2.3.0.
deprecated The module.loaders syntax is deprecated since webpack 2. Using it with ejs-compiled-loader will cause warnings.
fix Use module.rules with the use property instead of loaders.
gotcha 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.
fix Example: use: 'ejs-compiled-loader?delimiter=?' or specify in options: use: { loader: 'ejs-compiled-loader', options: { delimiter: '?' } }
gotcha The loader returns a function, not a string. Attempting to assign the output directly to innerHTML will fail if not invoked.
fix Ensure you call the template function with data: const html = template(data);
npm install ejs-compiled-loader
yarn add ejs-compiled-loader
pnpm add ejs-compiled-loader

Shows basic webpack configuration and how to import an .ejs template, then render it with data.

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.ejs$/,
        use: 'ejs-compiled-loader'
      }
    ]
  }
};

// app.js
import template from './file.ejs';
const html = template({ name: 'World' });
console.log(html); // => '<p>Hello World</p>'