vite-pug-adapter 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/package.json +1 -1
- package/src/index.js +1 -1
package/README.md
CHANGED
|
@@ -4,14 +4,13 @@ A simple Vite plugin that serves Pug files directly without physical HTML files.
|
|
|
4
4
|
## Features
|
|
5
5
|
- No dirties. No physical HTML in your root.
|
|
6
6
|
- Simple usage. No configs.
|
|
7
|
-
-
|
|
7
|
+
- Serves Pug files to Vite as if they were html files.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
```bash
|
|
11
11
|
npm install -D vite-pug-adapter pug
|
|
12
12
|
```
|
|
13
|
-
```
|
|
14
|
-
//vite.config.js
|
|
13
|
+
```javascript
|
|
15
14
|
// vite.config.js
|
|
16
15
|
import vite_pug_adapter from 'vite-pug-adapter';
|
|
17
16
|
|
|
@@ -20,6 +19,12 @@ export default {
|
|
|
20
19
|
};
|
|
21
20
|
```
|
|
22
21
|
|
|
22
|
+
## Minimal Example
|
|
23
|
+
Following is ready-to-run example.
|
|
24
|
+
Try it by using ``npm run dev`` after cloning it.
|
|
25
|
+
|
|
26
|
+
https://github.com/mtugb/-vite-pug-adapter-example1
|
|
27
|
+
|
|
23
28
|
## Caution
|
|
24
|
-
This **only** compiles Pug files in your root dir, then if you need to put Pug files in other places such as
|
|
29
|
+
This **only** compiles Pug files in your root dir, then if you need to put Pug files in other places, such as ``/src``, you should use another module.
|
|
25
30
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -5,7 +5,7 @@ const vite_pug_adapter = {
|
|
|
5
5
|
configureServer: function (server) {
|
|
6
6
|
server.middlewares.use(async (req, res, next) => {
|
|
7
7
|
// normal page
|
|
8
|
-
if (/^\/[a-zA-
|
|
8
|
+
if (/^\/[a-zA-Z0-9_-]*$/.test(req.url)) {
|
|
9
9
|
const pug_path = req.url === "/" ? "/index" : req.url;
|
|
10
10
|
try {
|
|
11
11
|
let html = pug.renderFile(`${process.cwd()}${pug_path}.pug`);
|