{"id":20226,"library":"mustache-loader","title":"mustache-loader","description":"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.","status":"active","version":"1.4.3","language":"javascript","source_language":"en","source_url":"git://github.com/deepsweet/mustache-loader","tags":["javascript","webpack","loader","mustache","hogan"],"install":[{"cmd":"npm install mustache-loader","lang":"bash","label":"npm"},{"cmd":"yarn add mustache-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add mustache-loader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for Mustache template compilation","package":"hogan.js","optional":false},{"reason":"Peer dependency for loader interface","package":"webpack","optional":false}],"imports":[{"note":"The loader exports the compiled template as a function by default. Named import will not work.","wrong":"import { template } from './file.html';","symbol":"default (template function)","correct":"import template from './file.html';"},{"note":"CommonJS returns the function directly, not an object.","wrong":"const { template } = require('./file.html');","symbol":"require (CommonJS)","correct":"const template = require('./file.html');"},{"note":"When using noShortcut option, the returned value is a Hogan template object with a render method.","wrong":"","symbol":"Hogan template object (with noShortcut)","correct":"const template = require('./file.html'); const html = template.render({foo: 'bar'});"}],"quickstart":{"code":"// webpack.config.js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.html$/,\n        use: 'mustache-loader',\n      },\n    ],\n  },\n};\n\n// app.js\nimport template from './template.html';\nconst html = template({ name: 'World' });\nconsole.log(html);","lang":"javascript","description":"Shows basic webpack configuration to use mustache-loader and how to import and use a compiled template."},"warnings":[{"fix":"Use module.rules array with use property for webpack 2+.","message":"Webpack 1.x uses 'loaders' array with 'loader' property; webpack 2+ uses 'rules' with 'use' property.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Specify exact webpack version range in your project.","message":"Peer dependency webpack \"*\" allows any version, but breaking changes exist across major versions.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Ensure mustache-loader is the last loader in the chain for those options to work.","message":"If another loader is chained after mustache-loader, minify, clientSide, and tiny options are ignored.","severity":"gotcha","affected_versions":">=1.3.0"},{"fix":"Use 'render' option when using 'tiny' with HtmlWebpackPlugin.","message":"The 'tiny' option will not emit the template source, which may break HtmlWebpackPlugin if used without 'render'.","severity":"gotcha","affected_versions":">=1.2.0"},{"fix":"Use a synchronous function or wrap in a data property.","message":"When using 'render' as a function, ensure it returns an object synchronously; otherwise rendering may fail.","severity":"gotcha","affected_versions":">=1.3.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Call template({}) directly instead of template.render({}). If you need partials, add '?noShortcut' to the loader.","cause":"Using template.render() without the 'noShortcut' option (template is already rendered HTML string).","error":"Module build failed: TypeError: Cannot read property 'render' of undefined"},{"fix":"Run: npm install hogan.js","cause":"hogan.js is a peer dependency not installed automatically.","error":"Module not found: Error: Can't resolve 'hogan.js'"},{"fix":"Use query string format e.g., 'mustache-loader?minify' or options object with only allowed keys: minify, noShortcut, clientSide, tiny, render.","cause":"Using an options object with invalid keys or format (e.g., webpack 2+ query syntax change).","error":"Invalid options object. Mustache Loader has been initialized using an options object that does not match the API schema."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}