You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A plugin that makes [Vite](https://vitejs.dev/) parse `<pug file="example.pug"></pug>` in your `index.html`. The rendered template replaces this tag with the compiled markup.
5
+
A plugin that makes [Vite](https://vitejs.dev/) parse `<pug src="example.pug"></pug>` in your `index.html`. The rendered template replaces this tag with the compiled markup.
6
6
7
-
> :information_source:**Vue** single file components don't require this plugin, adding [Pug](https://www.npmjs.com/package/pug) to the dependency list is enough. — aka `npm i -D pug`
7
+
> :information_source:**Vue** single file components don’t require this plugin, adding [Pug](https://www.npmjs.com/package/pug) to the dependency list is enough. — aka `npm i -D pug`
8
8
9
-
- Handle self-closing tags.
10
-
- Works with multiple `pug` tags.
11
-
- Generated _TypeScript_ declarations.
12
-
- Common JS module but tested as ES module.
13
-
- Auto-reload browser when saving changes to `.pug` file.
9
+
## Features (exists and awaiting)
10
+
11
+
-[x] CommonJS and ES module builds.
12
+
-[x] Handle self-closing `pug` tags.
13
+
-[x] Works with multiple `pug` tags.
14
+
-[x] Generated _TypeScript_ declarations.
15
+
-[x] Reload when saving changes on a `.pug` file.
16
+
-[x] Support Pug local variables.
17
+
-[ ]_Experimental hot module reloading functionality._
18
+
-[ ]_Handle adding or removing files._
14
19
15
20
## Installation
16
21
17
22
Using npm:
18
23
19
-
```console
20
-
npm install vite-plugin-pug --save-dev
24
+
```sh
25
+
$ npm install vite-plugin-pug --save-dev
21
26
```
22
27
23
28
## Configuration
24
29
25
30
Create a `vite.config.js`[configuration file](https://vitejs.dev/config/) and import the plugin:
26
31
27
32
```js
33
+
// vite.config.(js|ts)
28
34
import { defineConfig } from"vite"
29
35
importpugPluginfrom"vite-plugin-pug"
30
36
37
+
constoptions= { pretty:true } // FIXME: pug pretty is deprecated!
38
+
constlocals= { name:"My Pug" }
39
+
31
40
exportdefaultdefineConfig({
32
41
plugins: [
33
-
pugPlugin()
42
+
pugPlugin(options, locals)
34
43
]
35
44
})
36
45
```
37
46
38
-
### Plugin Options
47
+
### Plugin Parameters
39
48
40
-
Accept [Pug options](https://pugjs.org/api/reference.html#options) as an optional parameter.
| locals | optional | Data object with Pug locals. |
48
53
49
54
## Usage
50
55
56
+
### Simple
57
+
51
58
Create a template file.
52
59
53
60
```pug
@@ -56,24 +63,28 @@ h1 Hello World
56
63
p I'm a cool Vite project!
57
64
```
58
65
59
-
Embed `pug` tag with `file` attribute somewhere.
66
+
Embed `pug` tag with `src` attribute somewhere.
60
67
61
68
```html
62
69
<!-- index.html -->
63
70
<html>
64
-
<body>
65
-
<pugfile="index.pug" />
66
-
<scripttype="module"src="/main.ts"></script>
67
-
</body>
71
+
<body>
72
+
<pugsrc="index.pug" />
73
+
<scripttype="module"src="/main.ts"></script>
74
+
</body>
68
75
</html>
69
76
```
70
77
71
78
That's it.
72
79
73
-
> :bulb: Check out **an example** implementation [in this repository](https://github.com/SubZtep/css-tetris-3d).
80
+
> :bulb: Check out **its starter** implementation [in this repository](https://github.com/SubZtep/css-tetris-3d).
81
+
82
+
## Example
83
+
84
+
Please find the [examples](examples/multipage) folder in this repository.
74
85
75
86
## Contribution
76
87
77
-
~~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](https://github.com/marlonmarcello/vite-plugin-pug) Pug plugins made me make one quickly. It does the job to me, I will extend it when I need it. :suspect:
88
+
~~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](https://github.com/marlonmarcello/vite-plugin-pug) Pug plugins made me make one quickly. It does the job to me, I will extend it when I need it. :suspect:
78
89
79
-
If it doesn't match with your setup please [start a new discussion](https://github.com/SubZtep/vite-plugin-pug/discussions/new) about it, I'm interested to see other workflows. If something is simply not working, please [raise an issue](https://github.com/SubZtep/vite-plugin-pug/issues/new). **PRs certainly welcome!** (.❛ ᴗ ❛.)
90
+
If it doesn't match with your setup please [start a new discussion](https://github.com/SubZtep/vite-plugin-pug/discussions/new) about it, I'm interested to see other workflows. If something is simply not working, please [raise an issue](https://github.com/SubZtep/vite-plugin-pug/issues/new). **PRs certainly welcome!** (.❛ ᴗ ❛.)
0 commit comments