forked from DanielXMoore/Civet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild-plugin.civet
46 lines (40 loc) · 910 Bytes
/
esbuild-plugin.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
36
37
38
39
40
41
42
43
44
45
46
/**
@file esbuild plugin for Civet language
@example
```javascript
import esbuild from 'esbuild'
import civetPlugin from '@danielx/civet/esbuild-plugin'
esbuild.build({
...,
plugins: [
civetPlugin
]
}).catch(() => process.exit(1))
```
*/
{ readFile } := require 'fs/promises'
path := require 'path'
// NOTE: this references the built version of the module, not the source
{ compile } := require "../dist/main.js"
module.exports = {
name: 'civet'
setup(build)
build.onLoad {
filter: /\.civet$/
}, (args) ->
try
source := await readFile args.path, 'utf8'
filename := path.relative(process.cwd(), args.path)
compiled := compile source, {
filename
inlineMap: true
js: true
}
return
contents: compiled
catch e
return
errors: [{
text: e.message
}]
}