GithubHelp home page GithubHelp logo

subztep / vite-plugin-pug Goto Github PK

View Code? Open in Web Editor NEW
44.0 3.0 8.0 424 KB

Vite plugin for transform Pug templates into HTML

Home Page: https://www.npmjs.com/package/vite-plugin-pug

License: The Unlicense

TypeScript 100.00%
vite vite-plugin pug jade

vite-plugin-pug's Introduction

vite-plugin-pug

test

A plugin that makes Vite parse <pug src="example.pug"></pug> in your index.html. The rendered template replaces this tag with the compiled markup.

ℹ️ Vue single file components don’t require this plugin, adding Pug to the dependency list is enough. — aka npm i -D pug

Features

  • CommonJS and ES module builds.
  • Handle self-closing pug tags.
  • Works with multiple pug tags.
  • Generated TypeScript declarations.
  • Reload when saving changes on a .pug file.
  • Support Pug local variables.
  • Templates for multiple inputs.
  • Experimental hot module reloading functionality.
  • Handle adding or removing files.

Add to a project

Installation

Choose your appropriate choice:

$ npm i -D vite-plugin-pug
$ pnpm add -D vite-plugin-pug
$ yarn add -D vite-plugin-pug

Configuration

Create a vite.config.js configuration file and import the plugin:

// vite.config.(js|ts)
import { defineConfig } from "vite"
import pugPlugin from "vite-plugin-pug"

const options = { pretty: true } // FIXME: pug pretty is deprecated!
const locals = { name: "My Pug" }

export default defineConfig({
  plugins: [pugPlugin(options, locals)],
})

Plugin Parameters

Name Required Description
options optional Plugin options object.
locals optional Data object with Pug locals.

Plugin Options

Name Required Description
... optional Anything from Pug options object.
localImports optional If true, use relative imports in the pug src attribute.

Usage

Simple

Create a template file.

//- index.pug
h1 Hello World
p I'm a cool Vite project!

Embed pug tag with src attribute somewhere.

<!-- index.html -->
<html>
  <body>
    <pug src="index.pug" />
    <script type="module" src="/main.ts"></script>
  </body>
</html>

That's it.

💡 Check out its starter implementation in this repository.

Examples

Please find the examples folder in this repository.

Contribution

After Rollup I started to use Vite recently but this is not a reason to leave my beloved template format behind. Its lack of active Pug plugins made me make one quickly. It does the job to me, I will extend it when I need it. :suspect:

If it doesn't match with your setup please start a new discussion about it, I'm interested to see other workflows. If something is simply not working, please raise an issue. PRs certainly welcome! (.❛ ᴗ ❛.)

vite-plugin-pug's People

Contributors

ai avatar raiondesu avatar subztep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vite-plugin-pug's Issues

how use vite env in pug file

how use vite env in pug file
eg

file .env.foo

VITE_BAR = 123.jpg

file index.pug

img(src=import.meta.<wbr>.foo.VITE_BAR)

thank you

module not parsed when in pug

Hello,

Trying to make this exciting plugin work for me. My index.pug contains this valid markup:

    script(type='module').
        import "beercss";

... but Vite dev does not compile the module, unless I move it to index.html. My index.html is

<pug src='./index.pug' />

Please help. (Also, the ideal workflow would be to have index.pug as entry, but the tag is an acceptable workaround.)

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.