Giter Site home page Giter Site logo

rspack-contrib / rsbuild-plugin-pug Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 84 KB

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

License: MIT License

TypeScript 85.40% JavaScript 5.79% Pug 3.46% Vue 5.34%
rsbuild rsbuild-plugin rspack

rsbuild-plugin-pug's Introduction

@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.

npm version license

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.

  • Type: Object | Function | undefined
  • Default:
const defaultOptions = {
  doctype: "html",
  compileDebug: false,
};
  • Example 1: Pass in a configuration object that will be merged with the default options using Object.assign.
pluginPug({
  pugOptions: {
    doctype: "xml",
  },
});
  • Example 2: Pass in a configuration function. The default configuration will be passed as the first argument, and you can directly modify the configuration object or return a value as the final result.
pluginPug({
  pugOptions(config) {
    config.doctype = "xml";
  },
});

License

MIT.

rsbuild-plugin-pug's People

Contributors

chenjiahan avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

friesencr

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.