Pug loader module for Webpack
Clone or download
Latest commit 99e7e12 Mar 29, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
test Propagate async errors to webpack (#78) Feb 24, 2017
.editorconfig Add .editorconfig Jul 24, 2016
.gitignore Initial commit Apr 6, 2012
.npmignore Ignore tests when publishing Aug 23, 2016
CHANGELOG.md 2.3.0 Aug 23, 2016
LICENSE.md Add a LICENSE file Jul 24, 2016
README.md Added filters option (#108) Mar 29, 2018
index.js Added filters option (#108) Mar 29, 2018
package.json Release 2.4.0 Mar 29, 2018
stringify.loader.js Automatically detect includes Oct 29, 2013



Pug loader for webpack.


var template = require("pug-loader!./file.pug");
// => returns file.pug content as template function

// or, if you've bound .pug to pug-loader
var template = require("./file.pug");

var locals = { /* ... */ };

var html = template(locals);
// => the rendered HTML

For more information on how to use webpack loaders, check the official documentation.

In order to obtain the rendered HTML at compile time, combine this loader with apply-loader:

var html = require("apply-loader!pug-loader!./file.pug");
// => the HTML is rendered at compile time

Legacy .jade files

pug-loader fully supports .jade files. Just use pug-loader with .jade files as you would with a .pug file.


If you are using includes, you must make sure that .pug (and if needed for legacy files, .jade) is bound to pug-loader. Check the webpack documentation on how to do that for CLI and for configuration files.


The following options are available to be set for the loader. They are all mapped directly to Pug options, unless pointed out otherwise.

  • doctype
    • Unlike Pug, it defaults to "html" if not set
  • globals
  • self
  • plugins
    • Note that you cannot specify any Pug plugins implementing read or resolve hooks, as those are reserved for the loader
  • pretty
  • filters
  • root
    • webpack uses its own file resolving mechanism, so while it is functionally equivalent to the Pug option with the same name, it is implemented differently

Embedded resources

Try to use require for all your embedded resources, to process them with webpack.


Remember, you need to configure loaders for these file types too. You might be interested in the file loader.