1. pug-plain-loader
Pug to plain html loader for webpack
pug-plain-loader
Package: pug-plain-loader
Created by: yyx990803
Last modified: Fri, 13 May 2022 16:12:16 GMT
Version: 1.1.0
License: MIT
Downloads: 231,390
Repository: https://github.com/yyx990803/pug-plain-loader

Install

npm install pug-plain-loader
yarn add pug-plain-loader

pug-plain-loader

A loader that simply compiles pug templates into HTML.

Installation

Note pug is a peer dependency, so make sure to install both:

 npm install -D pug-plain-loader pug

Usage

This loader is mostly intended to be used alongside vue-loader v15+, since it now requires using webpack loaders to handle template preprocessors. There's also pug-html-loader which unfortunately is out-of-date and not actively maintained.

If you are only using this loader for templating in single-file Vue components, simply configure it with:

 {
  module: {
    rules: [
      {
        test: /\.pug$/,
        loader: 'pug-plain-loader'
      }
    ]
  }
}

This will apply this loader to all <template lang="pug"> blocks in your Vue components.

If you also intend to use it to import .pug files as HTML strings in JavaScript, you will need to chain raw-loader after this loader. Note however adding raw-loader would break the output for Vue components, so you need to have two rules, one of them excluding Vue components:

 {
  module: {
    rules: [
      {
        test: /\.pug$/,
        oneOf: [
          // this applies to pug imports inside JavaScript
          {
            exclude: /\.vue$/,
            use: ['raw-loader', 'pug-plain-loader']
          },
          // this applies to <template lang="pug"> in Vue components
          {
            use: ['pug-plain-loader']
          }
        ]
      }
    ]
  }
}

Options

See Pug compiler options.

The doctype option is set to html by default, since most Vue templates are HTML fragments without explicit doctype.

An additional option data can be used to pass locals for the template, although this is typically not recommended when using in Vue components.

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code