forked from Ragudos/todo-app-frontend-mentor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.plugin.mjs
33 lines (29 loc) · 940 Bytes
/
esbuild.plugin.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { promises } from "node:fs";
import { dirname } from "node:path";
import pug from "pug";
export default function pugPlugin() {
return {
name: "pug",
setup(build) {
build.onLoad(
{
filter: /\.(jade|pug)$/
},
async function(args) {
const template = await promises.readFile(args.path, "utf-8");
const contents = pug.compileClient(
template,
{
filename: args.path,
basedir: dirname(args.path),
}
);
return {
contents: `${contents}\n\nexport default template;`,
loader: "js"
};
}
)
}
};
};