Registry / web-framework / mustache-loader

mustache-loader

JSON →
library1.4.3jsnpmunverified

A webpack loader that compiles Mustache templates using Hogan.js. Current stable version is 1.4.3, with last release in 2016. It has peer dependencies on hogan.js and webpack (supports webpack 1.x, 2.x, and 4.x beta). Supports options like minification via html-minifier, tiny output, client-side compilation, and direct rendering. Differentiators include optional noShortcut for partials and render function for hot reloading. It is a straightforward conversion from Mustache templates to JavaScript functions, with minimal overhead.

npm install mustache-loader
INSTALL
IMPORT
SIG · MUSTACHE-LOADER
M
mustache-loader
web-frameworkjavascriptv1.4.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (template function)
import template from './file.html';
import { template } from './file.html';
The loader exports the compiled template as a function by default. Named import will not work.
require (CommonJS)
const template = require('./file.html');
const { template } = require('./file.html');
CommonJS returns the function directly, not an object.
Hogan template object (with noShortcut)
const template = require('./file.html'); const html = template.render({foo: 'bar'});
When using noShortcut option, the returned value is a Hogan template object with a render method.

Shows basic webpack configuration to use mustache-loader and how to import and use a compiled template.

// webpack.config.js module.exports = { module: { rules: [ { test: /\.html$/, use: 'mustache-loader', }, ], }, }; // app.js import template from './template.html'; const html = template({ name: 'World' }); console.log(html);
Debug
Known issues
breakingWebpack 1.x uses 'loaders' array with 'loader' property; webpack 2+ uses 'rules' with 'use' property.
fix
Use module.rules array with use property for webpack 2+.
affects: >=1.0.0
deprecatedPeer dependency webpack "*" allows any version, but breaking changes exist across major versions.
fix
Specify exact webpack version range in your project.
affects: >=1.0.0
gotchaIf another loader is chained after mustache-loader, minify, clientSide, and tiny options are ignored.
fix
Ensure mustache-loader is the last loader in the chain for those options to work.
affects: >=1.3.0
gotchaThe 'tiny' option will not emit the template source, which may break HtmlWebpackPlugin if used without 'render'.
fix
Use 'render' option when using 'tiny' with HtmlWebpackPlugin.
affects: >=1.2.0
gotchaWhen using 'render' as a function, ensure it returns an object synchronously; otherwise rendering may fail.
fix
Use a synchronous function or wrap in a data property.
affects: >=1.3.0
Errors
Common errors & fixes
Module build failed: TypeError: Cannot read property 'render' of undefined
Using template.render() without the 'noShortcut' option (template is already rendered HTML string).
fix
Call template({}) directly instead of template.render({}). If you need partials, add '?noShortcut' to the loader.
Module not found: Error: Can't resolve 'hogan.js'
hogan.js is a peer dependency not installed automatically.
fix
Run: npm install hogan.js
Invalid options object. Mustache Loader has been initialized using an options object that does not match the API schema.
Using an options object with invalid keys or format (e.g., webpack 2+ query syntax change).
fix
Use query string format e.g., 'mustache-loader?minify' or options object with only allowed keys: minify, noShortcut, clientSide, tiny, render.
Upgrade
Version history
1.4.3latest on npm
Audit
Dependencies
hogan.jsrequiredPeer dependency for Mustache template compilation
webpackrequiredPeer dependency for loader interface
Agent activity
4 hits · last 30 days
node
4
Resources
mustache-loader — npm install mustache-loader · libregistry