More Premium Hugo Themes Premium Vue Themes

Pug Loader

Pug loader for Webpack renders pug to HTML or template function

Pug Loader

Pug loader for Webpack renders pug to HTML or template function

Author Avatar Theme by webdiscus
Github Stars Github Stars: 83
Last Commit Last Commit: Feb 4, 2025 -
First Commit Created: Apr 29, 2023 -
default image

Overview:

The Pug loader is a tool that can render Pug files into HTML or compile them into a template function. It supports resolving paths and aliases for extends, includes, and requires. It also allows for the use of indents in Vue templates. The Pug plugin, on the other hand, enables the use of Pug files in webpack entry and generates HTML files that contain the hashed output of JS and CSS filenames specified in the Pug template. It eliminates the need to define scripts and styles in the webpack entry and import styles in JavaScript to inject them into HTML.

Features:

  • Renders Pug into pure HTML strings
  • Compiles Pug into a template function for usage in JavaScript
  • Generates a template function with both CommonJS and ESM syntax
  • Resolves aliases from webpack resolve.alias and tsconfig.json compilerOptions.paths
  • Resolves required images in the attribute srcset of img tags
  • Resolves required JavaScript modules or JSON in Pug
  • Provides integrated Pug filters for escaping, code highlighting, and markdown support
  • Includes usage examples and a demo app

Installation:

To install the Pug loader and plugin, you have two options:

  1. Using the pug-plugin:
  • Install the pug-plugin:
npm install pug-plugin --save-dev
  • Note: The pug-plugin already includes the Pug loader, so there is no need to install an additional Pug loader.
  1. Using a pug-loader:
  • Compile Pug files defined in webpack entry using the pug-plugin, which is a more intuitive and easier approach.
  • Compile Pug files defined in the html-webpack-plugin using a pug-loader, which is a more complex and non-intuitive approach.
  • For more details and examples, please refer to the pug-plugin site.

Summary:

The Pug loader is a versatile tool that allows for the rendering and compilation of Pug files. It provides features such as resolving paths and aliases, support for indents in Vue templates, and integrated Pug filters for escaping, code highlighting, and markdown support. The Pug plugin, on the other hand, eliminates the need for additional plugins such as html-webpack-plugin and mini-css-extract-plugin by processing files from the webpack entry and generating HTML files with hashed CSS and JS output filenames. Overall, the Pug loader and plugin provide efficient and easy ways to work with Pug files in webpack projects.