Home

Awesome

@rsbuild/plugin-pug

An Rsbuild plugin to provide support for the Pug template engine.

Pug is a robust, elegant, feature rich template engine for Node.js.

<p> <a href="https://npmjs.com/package/@rsbuild/plugin-pug"> <img src="https://img.shields.io/npm/v/@rsbuild/plugin-pug?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" /> </a> <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" /> </p>

Usage

Install:

npm add @rsbuild/plugin-pug -D

Add plugin to your rsbuild.config.ts:

// rsbuild.config.ts
import { pluginPug } from "@rsbuild/plugin-pug";

export default {
  plugins: [pluginPug()],
};

Using Pug Templates

After the plugin registration is completed, Rsbuild will automatically parse template files with the .pug extension and compile them using the Pug template engine.

For example, first create a src/index.pug file, and point to that file using html.template:

export default {
  html: {
    template: "./src/index.pug",
  },
};

Then, you can use Pug syntax in the index.pug template:

<!-- Input -->
p Hello #{text}!

<!-- Output -->
<p>Hello World!</p>

Please refer to the Pug documentation for a complete understanding of Pug's usage.

Using in Vue

When using Vue, you can use Pug syntax in the template of .vue files:

<template lang="pug">
button.my-button(@click='count++') Count is: {{ count }}
</template>

<script>
import { ref } from "vue";

export default {
  setup() {
    const count = ref(0);

    return {
      count,
    };
  },
};
</script>

Options

pugOptions

Used to set the compilation options for Pug. For detailed options, please refer to the Pug API Reference.

const defaultOptions = {
  doctype: "html",
  compileDebug: false,
};
pluginPug({
  pugOptions: {
    doctype: "xml",
  },
});
pluginPug({
  pugOptions(config) {
    config.doctype = "xml";
  },
});

License

MIT.