包详细信息

pug-loader

pugjs173kMIT2.4.0

Pug loader module for webpack

自述文件

pug-loader

Pug loader for webpack.

Usage

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.

Includes

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.

Options

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.

div
  img(src=require("./my/image.png"))

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

License

MIT

更新日志

Change log

2.3.0 / 2016-08-22

  • Use explicit pug-walk dependency; fixes installation on npm v2
  • Allow setting Pug options from webpack.config.js's pugLoader property

2.2.1 / 2016-08-06

  • Minor README correction
  • Remove unused web_modules/fs.js

2.2.0 / 2016-07-26

  • Revert to v2.0.0
    • v2.1.0 has a bug that prevents users from having working inclusion if pug-loader has already been bound

2.1.0 / 2016-07-25

  • Make it unnecessary to bind pug-loader in order to use includes

2.0.0 / 2016-07-25

  • Rename package from jade-loader to pug-loader
    • pug-loader@1 has been renamed as pug-load
  • Update to Pug 2.0.0
    • Reimplement as a Pug plugin
  • Add plugins option
  • Add a change log (the file you are reading!) and a license file
  • Enrich the README