-
Notifications
You must be signed in to change notification settings - Fork 35
/
bun-civet.civet
35 lines (29 loc) · 1008 Bytes
/
bun-civet.civet
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
34
35
###
Bun plugin for Civet files. Simply follow the steps below:
1. Create bunfig.toml if it doesn't exist
2. Add the following line:
preload = ["@danielx/civet/bun-civet"]
3. Get plugin from npm:
bun add -D @danielx/civet
After that, you can use .civet files with the Bun cli, like:
$ bun file.civet
###
import { plugin, file } from 'bun'
//import { plugin, file, Transpiler } from 'bun'
await plugin {
name: 'Civet loader'
setup(builder)
{ compile } := await import('./main.mjs')
//transpiler := new Transpiler loader: 'tsx'
builder.onLoad filter: /\.civet$/, ({path}) =>
source := file path |> .text() |> await
// Compiling and running at the same time, so enable comptime
// to ensure any async promises get resolved
contents .= await compile source, comptime: true
// Transpile directly as workaround to loader spec below not working
//contents = await transpiler.transform contents
return {
contents
loader: 'tsx'
}
}