Gathering detailed insights and metrics for pug-plugin
Gathering detailed insights and metrics for pug-plugin
Gathering detailed insights and metrics for pug-plugin
Gathering detailed insights and metrics for pug-plugin
Renders Pug template to HTML or template function. Resolves source files of scripts, styles, images in Pug . Uses Pug template as entry point.
npm install pug-plugin
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (61.63%)
HTML (16.12%)
Pug (13.63%)
SCSS (4.94%)
CSS (3.67%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
ISC License
71 Stars
103 Commits
8 Forks
2 Watchers
1 Branches
3 Contributors
Updated on Apr 01, 2025
Latest Version
6.0.0
Package Id
pug-plugin@6.0.0
Unpacked Size
45.41 kB
Size
14.10 kB
File Count
6
NPM Version
10.9.0
Node Version
22.11.0
Published on
Jan 28, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
4
1
24
The Pug Plugin generates static HTML or template function from Pug template containing source files of scripts, styles, images, fonts and other resources, similar to how it works in Vite. This plugin allows using a template file as an entry point.
The plugin resolves source files of assets in templates and replaces them with correct output URLs in the generated HTML. The resolved assets will be processed via Webpack plugins/loaders and placed into the output directory. You can use a relative path or Webpack alias to a source file.
A template imported in JS will be compiled into template function. You can use the template function in JS to render the template with variables in runtime on the client-side in the browser.
script
and style
source files directly in Pug:
link(href="./style.scss" rel="stylesheet")
script(src="./app.tsx" defer="defer")
href
src
srcset
etc. using relative path or alias:
link(href="../images/favicon.svg" type="image/svg" rel=icon)
img(src="@images/pic.png" srcset="@images/pic400.png 1x, @images/pic800.png 2x")
link
and script
tags.:escape
:code
:highlight
:markdown
.See the full list of features.
‼️ Note
The
pug-plugin
since version5.0.0
is essentially the html-bundler-webpack-plugin under the hood, pre-configured to use Pug templates. All features and options of html-bundler-webpack-plugin are now available inpug-plugin
.
⚠️ Warning
Compared to the version
4.x
, in the new version5.x
the source asset file can be specified in a template without therequire()
function. For compatibility, therequire()
function is still supported.OLD syntax
1link(href=require("./style.scss") rel="stylesheet")
The asset path is relative to the partial template or can be as the webpack alias.
NEW syntax
1link(href="./style.scss" rel="stylesheet")
The asset path is relative to the entry template or can be as the webpack alias.
See the full list of the BREAKING CHANGES in v5.
Install the pug-plugin
:
1npm install pug-plugin --save-dev
Install additional packages for styles:
1npm install css-loader sass sass-loader --save-dev
For example, there is the Pug template with source asset files ./src/views/index.pug:
1html 2 head 3 //- relative path to SCSS source file 4 link(href="../scss/style.scss" rel="stylesheet") 5 //- relative path to TypeScript source file 6 script(src="../app/main.js" defer="defer") 7 body 8 h1 Hello World! 9 //- relative path to image source file 10 img(src="../assets/images/picture1.png") 11 //- Webpack alias as path (src/assets/images/) to image source file 12 img(src="@images/picture2.png")
The minimal webpack config:
1const PugPlugin = require('pug-plugin'); 2 3module.exports = { 4 plugins: [ 5 new PugPlugin({ 6 entry: { 7 // define many page templates here 8 index: 'src/views/index.pug', // => dist/index.html 9 }, 10 js: { 11 // JS output filename 12 filename: 'js/[name].[contenthash:8].js', 13 }, 14 css: { 15 // CSS output filename 16 filename: 'css/[name].[contenthash:8].css', 17 }, 18 }), 19 ], 20 module: { 21 rules: [ 22 { 23 test: /\.(s?css|sass)$/, 24 use: ['css-loader', 'sass-loader'], 25 }, 26 { 27 test: /\.(ico|png|jp?g|webp|svg)$/, 28 type: 'asset/resource', 29 generator: { 30 filename: 'img/[name].[hash:8][ext][query]', 31 }, 32 }, 33 ], 34 }, 35};
Warning
No additional pug or html loaders required.
The generated HTML contains URLs of the output filenames:
1<html> 2 <head> 3 <link href="css/style.05e4dd86.css" rel="stylesheet" /> 4 <script src="js/main.f4b855d8.js" defer="defer"></script> 5 </head> 6 <body> 7 <h1>Hello World!</h1> 8 <img src="img/picture1.58b43bd8.png" /> 9 <img src="img/picture2.bd858b43.png" /> 10 </body> 11</html>
The Pug plugin has all the options of the HTML Bundler Plugin
, plus a few options specific to Pug plugin.
pretty
Type: 'auto'|boolean|Object
Default: false
The Pug compiler generate minimized HTML.
For formatting generated HTML is used the js-beautify with the following default options
:
1{ 2 html: { 3 indent_size: 2, 4 end_with_newline: true, 5 indent_inner_html: true, 6 preserve_newlines: true, 7 max_preserve_newlines: 0, 8 wrap_line_length: 120, 9 extra_liners: [], 10 space_before_conditional: true, 11 js: { 12 end_with_newline: false, 13 preserve_newlines: true, 14 max_preserve_newlines: 2, 15 space_after_anon_function: true, 16 }, 17 css: { 18 end_with_newline: false, 19 preserve_newlines: false, 20 newline_between_rules: false, 21 }, 22 }, 23}
Possible values:
false
- disable formatting
true
- enable formatting with default options
'auto'
- in development
mode enable formatting with default options, in production
mode disable formatting,
use prettyOptions to customize options
{}
- enable formatting with custom options, this object are merged with default options
see options reference
prettyOptions
Type: Object
Default: null
When the pretty option is set to auto
or true
, you can configure minification options using the prettyOptions
.
Why the Pug Plugin since v5.0
based on html-bundler-webpack-plugin?
2021
The history of the creation of the pug-plugin
began back in October 2021.
In late 2021 I implemented the @webdiscus/pug-loader as а replacement for pug-loader because pug-loader
was outdated and had many issues.
2022
Until 2022 html-webpack-plugin
had no alternative.
Using html-webpack-plugin
caused me pain and suffering to configure webpack for rendering Pug templates containing various assets.
In early 2022, I started developing the pug-plugin
as a complete replacement for html-webpack-plugin
and many other "crutches".
During the year, the pug-plugin
has gained a lot of useful features and was able to replace the html-webpack-plugin
, mini-css-extract-plugin
and many other plugins and loaders.
2023
Based on the pug-plugin
code I decided to develop a universal html-bundler-webpack-plugin that would support all the most popular template engines, such as Eta, EJS, Handlebars, Nunjucks, Pug, TwigJS, and would be extendable for other template engines, e.g., LiquidJS.
During the year, this plugin has gained even more useful features and absorbed all the functionality of the pug-plugin
and the @webdiscus/pug-loader
.
2024
In early 2024, the pug-plugin
completely switched to the universal code of html-bundler-webpack-plugin
.
Starting from version 5.0
, the pug-plugin
is the html-bundler-webpack-plugin
unter the hood, pre-configured for Pug templates with the pre-installed pug
package.
The config of pug-plugin >= v5.0
:
1const PugPlugin = require('pug-plugin'); 2 3module.exports = { 4 plugins: [ 5 new PugPlugin({ 6 entry: { 7 index: 'src/views/home.pug', 8 }, 9 }), 10 ], 11};
The above configuration is equivalent to:
1const HtmlBundlerPlugin = require('html-bundler-webpack-plugin'); 2 3module.exports = { 4 plugins: [ 5 new HtmlBundlerPlugin({ 6 entry: { 7 index: 'src/views/home.pug', 8 }, 9 preprocessor: 'pug', // <= enable using Pug templating engine 10 }), 11 ], 12};
The heart of
pug-plugin
now beats in thehtml-bundler-webpack-plugin
.
@webdiscus/pug-loader
->pug-plugin
->html-bundler-webpack-plugin
->pug-plugin
No vulnerabilities found.
No security vulnerabilities found.